BigDecimail转为负数 BigDecimail 转负数negate()
new BigDecimail().negate() 返回负数
:
1 /**
2 * Returns a {@code BigDecimal} whose value is {@code (-this)},
3 * and whose scale is {@code this.scale()}.
4 *
5 * @return {@code -this}.
6 */
7 public BigDecimal negate() {
8 if (intCompact == INFLATED) {
9 return new ate(), INFLATED, scale, precision);
10 } else {
11 return valueOf(-intCompact, scale, precision);
12 }
13 }
bigdecimal转换为integer14
1 /**
2 * Trusted package private constructor.
3 * Trusted simply means if val is INFLATED, intVal could not be null and
4 * if intVal is null, val could not be INFLATED.
5 */
6 BigDecimal(BigInteger intVal, long val, int scale, int prec) {
7 this.scale = scale;
8 this.precision = prec;
9 this.intCompact = val;
10 this.intVal = intVal;
11 }
1/**
2 * Translates a {@code long} value into a {@code BigDecimal}
3 * with a scale of zero. This {@literal "static factory method"}
4 * is provided in preference to a ({@code long}) constructor
5 * because it allows for reuse of frequently used
6 * {@code BigDecimal} values.
7 *
8 * @param val value of the {@code BigDecimal}.
9 * @return a {@code BigDecimal} whose value is {@code val}.
10 */
11 static BigDecimal valueOf(long unscaledVal, int scale, int prec) {
12 if (scale == 0 && unscaledVal >= 0 && unscaledVal < zeroThroughTen.length) {
13 return zeroThroughTen[(int) unscaledVal];
14 } else if (unscaledVal == 0) {
15 return zeroValueOf(scale);
16 }
17 return new BigDecimal(unscaledVal == INFLATED ? INFLATED_BIGINT : null,
18 unscaledVal, scale, prec);
19 }
1 /**
2 * Sentinel value for {@link #intCompact} indicating the
3 * significand information is only available from {@code intVal}.
4 */
5 static final long INFLATED = Long.MIN_VALUE;
6
7/**
8 * A constant holding the minimum value a {@code long} can
9 * have, -2<sup>63</sup>.
10 */
11 @Native public static final long MIN_VALUE = 0x8000000000000000L; int与的相互转换
1int转bigdecimal
2
3
4BigDecimal number = new BigDecimal(0);
5
6int value=score;
7
8number=BigDecimal.valueOf((int)value);
9
1
2bigdecimal转int
3
4
5BigDecimal b=new BigDecimal(45.45);
6int a = b.intValue();
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论