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
, performedvalueof
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
Post a Comment