How does Double.intValue() work?
double, integer, java
Solution
To know the exact value of your double, you can use a BigDecimal:
System.out.println(new BigDecimal(254.9999999999999));
System.out.println(new BigDecimal(254.99999999999999));
prints:
254.9999999999998863131622783839702606201171875
255
So this is simply due to (limitations of) double precision...
Problem
This code ``` Double dbl = 254.9999999999999; Integer integ = dbl.intValue(); System.out.println(integ); ``` shows 254, but one "9" more ``` Double dbl = 254.99999999999999; Integer integ = dbl.intValue(); System.out.println(integ); ``` and it is already 255.. Why?