F
Forrest Hump
Can anyone tell me why the code sample below returns a different value for
variable b_OLD ?
The value I get for bd1 is 4.1624999999999996447286321199499070644378662109375.
Why does Java not keep it as 4.1625 ?
----------------
double b_OLD = 4.1625;
java.math.BigDecimal bd1 = new java.math.BigDecimal( b_OLD );
System.out.println("BEFORE ROUNDING: " + bd1);
bd1 = bd1.setScale(0, java.math.BigDecimal.ROUND_CEILING);
System.out.println("AFTER ROUNDING: " + bd1);
variable b_OLD ?
The value I get for bd1 is 4.1624999999999996447286321199499070644378662109375.
Why does Java not keep it as 4.1625 ?
----------------
double b_OLD = 4.1625;
java.math.BigDecimal bd1 = new java.math.BigDecimal( b_OLD );
System.out.println("BEFORE ROUNDING: " + bd1);
bd1 = bd1.setScale(0, java.math.BigDecimal.ROUND_CEILING);
System.out.println("AFTER ROUNDING: " + bd1);