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.

1 comment :

  1. I have read your blog its very attractive and impressive. I like it your blog.


    JavaEE Training in Chennai JavaEE Training in Chennai Core Java 8 Training in Chennai Java 8 Training in Chennai Java Online Training Java Online Training

    Java Training in Chennai Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

    ReplyDelete