我没有使用大小数得到正确的答案 [英] i am not get the correct annswer using big decimal
本文介绍了我没有使用大小数得到正确的答案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hai All
我要求舍入双倍价值
值= 16.415;
Hai All
I am ask to do the rounding the Double value
Value =16.415;
展开 | 选择 | Wrap | 行号
推荐答案
也许您想使用BigDecimal.ROUND_HALF_UP?
Perhaps you wanted to use BigDecimal.ROUND_HALF_UP instead?
也许您想使用BigDecimal.ROUND_HALF_UP代替?
Perhaps you wanted to use BigDecimal.ROUND_HALF_UP instead?
for ROUND_HALF_UP
1-> 16.41
2-> 16.43
3-> 16.43
4-> 16.45
5-> 16.45
6-> 16.46
7-> 16.48
8-> 16.48
9-> 16.5
对于在所有情况下测试的上面输入
for ROUND_HALF_UP
1->16.41
2->16.43
3->16.43
4->16.45
5->16.45
6->16.46
7->16.48
8->16.48
9->16.5
For Above input i tested in all cases
问题是你用于BigDecimal的构造函数。
使用String one即new BigDecimal("" + value);
阅读两个构造函数的API规范以找出差异。
The problem is the constructor you used for BigDecimal.
Use the String one i.e new BigDecimal("" + value);
Read the API specs for both constructors to find out the difference.
这篇关于我没有使用大小数得到正确的答案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文