Round Java float parseFloat

Given the following code, I want it to return "float = 32000.0001" Instead, it returns "float = 32000.0"

System.out.println("float = "+Float.parseFloat("32000.0001"));

What can I do to prevent / control rounding? The full value I want to return is not rounded

Solution

Float has only 24 bit precision, which is not enough to save the number of bits in the value Rounding is not due to parsing, but due to the size of the number If floating point is required, double must be used; If you need any precision, you must use BigDecimal

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>