Regarding BigDecimal

Posted by arav on Stack Overflow See other posts from Stack Overflow or by arav
Published on 2010-03-09T02:11:07Z Indexed on 2010/03/09 2:21 UTC
Read the original article Hit count: 336

Filed under:
|
|

i do the below java print command for this double variable double test=58.15; When i do a System.out.println(test); and System.out.println(new Double(test).toString()); It prints as 58.15.

When i do a System.out.println(new BigDecimal(test)) I get the below value 58.14999999999999857891452847979962825775146484375

I am able to understand "test" double variable value is internally stored as 58.1499999. But when i do the below two System.out.println i am getting the output as 58.15 and not 58.1499999.

System.out.println(test);

System.out.println(new Double(test).toString());

It prints the output as 58.15 for the above two.

Is the above System.out.println statements are doing some rounding of the value 58.1499999 and printing it as 58.15?

© Stack Overflow or respective owner

Related posts about java

Related posts about bigdecimal