Monday, June 20, 2011

Java Float class valueOf method automatically rounds string

I encountered this problem when I try to do something like:

Float.valueOf("123456.123");

The result Float value is automatically rounded to 123456.00.
In order to preserve the precision, I need to use Double.

Double.valueOf("123456.123");

BTW, my jdk version is 1.6.

3 comments :