在十进制Java后获取数字 [英] Getting numbers after decimal Java
本文介绍了在十进制Java后获取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要在小数点后面得到数字。
ex: 60。
4 - > 0.4
然而,何时
double a = 60.4%1;
它出现在 0.3999999999999986
/ p>
这是为什么?如何修复?
解决方案
使用定点类型
BigDecimal src = new BigDecimal(60.4);
BigDecimal a = src.remainder(BigDecimal.ONE);
Possible Duplicate:
Strange floating-point behaviour in a Java program
Why does JSP/JSTL division by 1000 sometimes give remainder?
I am trying to get the numbers after the decimal.
ex: 60.
4 -> 0.4
Yet, when do
double a = 60.4 % 1;
it comes out to be 0.3999999999999986
.
Why is this? And how could it be fixed?
解决方案
Use fixed-point types
BigDecimal src = new BigDecimal("60.4");
BigDecimal a = src.remainder(BigDecimal.ONE);
这篇关于在十进制Java后获取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文