A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
How to convert String to float with exact decimal value
Joined: Nov 10, 2008
Nov 18, 2009 21:42:25
When I convert a
value to float by using Float.valueOf(String), The return value is not containing last decimal.
Ex: String a = 2.50;
float b = Float.valueOf(a);
Now the float "b" is holding only upto 2.5. It is not converting String value to float properly. My requirement is to convert a String value to Float with exact decimals.
Please tell me how can I convert a String to float with complete decimals.
Joined: Oct 27, 2005
Nov 19, 2009 00:31:25
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions
How To Answer Questions
Joined: Jun 24, 2009
Nov 19, 2009 01:12:12
Joined: Oct 13, 2005
Nov 19, 2009 03:03:59
The primitive types don't store trailing 0s. Agree with Rob P.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: How to convert String to float with exact decimal value
Converting String value 2.0 into int
Float.valueOf() method and NumberFormatException
Float.valueOf is rounding 999999.99 to 1000000.00
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015