Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse String to Long using a specified locale (sv) and NumberFormat

I tried to parse a string (14 123) to a long in java using Swedish locale using this code:

String longString = "14 123"
NumberFormat swedishNumberFormat = NumberFormat.getInstance(new Locale("sv"));
System.out.println(swedishNumberFormat.parse(longString).longValue());

The output of this code is 14 (it should be 14123). As per this question I tried with both the sv and sv_SE locale but this time the result was identical in both cases.

According to http://www.localeplanet.com/java/sv/index.html and http://www.localeplanet.com/java/sv-SE/index.html the grouping separator in both cases is a space() so why does the string to long parsing not handle a, for the locale, properly formatted double value stored as string?

like image 692
d-b Avatar asked Oct 08 '14 10:10

d-b


1 Answers

Swedish, as French too, needs a hard. non-breaking space.

longString = longString.replace(' ', '\u00a0');

Cumbersome.

like image 101
Joop Eggen Avatar answered Sep 19 '22 15:09

Joop Eggen