Given the following code, I would expect it to return "float = 32000.0001". But instead, it returns "float = 32000.0".
System.out.println("float = "+Float.parseFloat("32000.0001"));
Is there something I can do to prevent/control the rounding? I want the full value returned with no rounding.
解决方案
A float has only 24 bits of precision, which is insufficient to hold the number of digits in your value. The rounding is not due to the parse but to the size of the number. You must use a double if you require floating point, or use BigDecimal if you need arbitrary precision.