java - NumberFormatException for String while parsing float -


this error caused due different system locale. use dot decimal separator.

i tried set default locale when application starts i'm getting same exception.

locale.setdefault(locale.us); 

stacktrace:

 caused by: java.lang.numberformatexception: input string: "6,2" @  sun.misc.floatingdecimal.readjavaformatstring(floatingdecimal.java:2043) @  sun.misc.floatingdecimal.parsefloat(floatingdecimal.java:122)  @  java.lang.float.parsefloat(float.java:451) 

it looks code using float.parsefloat. doesn't use locale settings. docs:

returns new float initialized value represented specified string, performed valueof method of class float.

and valueof has detailed grammar, , includes this:

to interpret localized string representations of floating-point value, use subclasses of numberformat.

so basically, default locale irrelevant here. if want parse "6,2" should using numberformat locale using comma decimal separator.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -