下面:
new MathContext(precision, RoundingMode.HALF_UP);
似乎工作.但是,以下内容返回错误:
new MathContext(precision, BigDecimal.ROUND_HALF_UP);
错误:
java: no suitable constructor found for MathContext(int,int)
constructor java.math.MathContext.MathContext(java.lang.String) is not applicable
(actual and formal argument lists differ in length)
constructor java.math.MathContext.MathContext(int,java.math.RoundingMode) is not applicable
(actual argument int cannot be converted to java.math.RoundingMode by method invocation conversion)
constructor java.math.MathContext.MathContext(int) is not applicable
(actual and formal argument lists differ in length)
最佳答案 请注意常量:
RoundingMode.HALF_UP
BigDecimal.ROUND_HALF_UP
根据Javadocs并根据源代码表示绝对相同:
public enum RoundingMode {
....
HALF_UP(BigDecimal.ROUND_HALF_UP),
....
}
最后
以上就是冷傲冬瓜最近收集整理的关于round up java_java – BigDecimal.ROUND_HALF_UP和RoundingMode.HALF_UP之间的区别?的全部内容,更多相关round内容请搜索靠谱客的其他文章。
发表评论 取消回复