BigDecimail 转负数negate()
new BigDecimail().negate() 返回负数
源码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15/** * Returns a {@code BigDecimal} whose value is {@code (-this)}, * and whose scale is {@code this.scale()}. * * @return {@code -this}. */ public BigDecimal negate() { if (intCompact == INFLATED) { return new BigDecimal(intVal.negate(), INFLATED, scale, precision); } else { return valueOf(-intCompact, scale, precision); } }
复制代码
1
2
3
4
5
6
7
8
9
10
11/** * Trusted package private constructor. * Trusted simply means if val is INFLATED, intVal could not be null and * if intVal is null, val could not be INFLATED. */ BigDecimal(BigInteger intVal, long val, int scale, int prec) { this.scale = scale; this.precision = prec; this.intCompact = val; this.intVal = intVal; }
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19/** * Translates a {@code long} value into a {@code BigDecimal} * with a scale of zero. This {@literal "static factory method"} * is provided in preference to a ({@code long}) constructor * because it allows for reuse of frequently used * {@code BigDecimal} values. * * @param val value of the {@code BigDecimal}. * @return a {@code BigDecimal} whose value is {@code val}. */ static BigDecimal valueOf(long unscaledVal, int scale, int prec) { if (scale == 0 && unscaledVal >= 0 && unscaledVal < zeroThroughTen.length) { return zeroThroughTen[(int) unscaledVal]; } else if (unscaledVal == 0) { return zeroValueOf(scale); } return new BigDecimal(unscaledVal == INFLATED ? INFLATED_BIGINT : null, unscaledVal, scale, prec); }
复制代码
1
2
3
4
5
6
7
8
9
10
11/** * Sentinel value for {@link #intCompact} indicating the * significand information is only available from {@code intVal}. */ static final long INFLATED = Long.MIN_VALUE; /** * A constant holding the minimum value a {@code long} can * have, -2<sup>63</sup>. */ @Native public static final long MIN_VALUE = 0x8000000000000000L;
int与bigdecimal的相互转换
复制代码
1
2
3
4
5
6
7
8
9
10int转bigdecimal BigDecimal number = new BigDecimal(0); int value=score; number=BigDecimal.valueOf((int)value);
复制代码
1
2
3
4
5
6bigdecimal转int BigDecimal b=new BigDecimal(45.45); int a = b.intValue();
最后
以上就是等待牛排最近收集整理的关于BigDecimail 转为负数的全部内容,更多相关BigDecimail内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复