开发者

parse float value 1000000.1 into String in java

开发者_C百科In my web application I have a version field that take float input values. But when using values like 1000000.1 (or larger) for the version it displays like 1.0E7. i tried several methods in Float wrapper class. but result still the same.

Thanks


Your problem is not in parsing but in formatting of your values. The value is correct and it is represented in java correctly. If you wish to change the format user either String.format() that provides C style formatting or java.text.NumberFormat.


System.out.printf("%f", Float.parseFloat("1.0E7")); outputs 10000000.000000

See http://ideone.com/3o6dO

Note that 1.0E7 is 1000000.0, not 1000000.1.


it probably has to do with your output format because 1.0E7 == 10000000


I think what you are looking for is the String.format(locale, msg, args) method.


Use String.valueOf(floatNumber)
Suggest use double instead of float

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜