概述
BigDecimail 转负数negate()
new BigDecimail().negate() 返回负数
源码:
/**
* 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);
}
}
/**
* 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;
}
/**
* 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);
}
/**
* 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的相互转换
int转bigdecimal
BigDecimal number = new BigDecimal(0);
int value=score;
number=BigDecimal.valueOf((int)value);
bigdecimal转int
BigDecimal b=new BigDecimal(45.45);
int a = b.intValue();
最后
以上就是等待牛排为你收集整理的BigDecimail 转为负数的全部内容,希望文章能够帮你解决BigDecimail 转为负数所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复