Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Converting string to float

843789Aug 23 2010 — edited Aug 25 2010
I have a decimal string "122339994" which i am trying to convert to float using Float.parseFloat. This results in incorrect value of 1.22339992E8.

I thought for floats precsision comes into effect after decimal places.

public static void main(String[] args) {

String floatString = "122339994";
float floatNumber = Float.parseFloat(floatString);
System.out.println("Float is "+floatNumber+". Now double "+Double.valueOf(floatString));
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 22 2010
Added on Aug 23 2010
3 comments
1,499 views