In creating a Java project, I ran into an issue with the standard Java libraries. I was using a DecimalFormat to format a double (truncating it from 3.4555555 to 3.45, for example). This worked fine for me, but when I sent it to someone else, they were getting an exception every time they started it. I was able to figure out from the stack trace that the DecimalFormat was converting it to 3,45 instead of 3.45 due to their locale, and Double.parseDouble didn't account for that. For the time being, I'm doing .replace(",", ".") on the string being parsed, but I don't know if there are other number formats in other locales. Is there any method that accounts for locale in the same way a DecimalFormat does?
Asked
Active
Viewed 67 times
0
-
1When you want to locale-aware parsing, you have to provide a specific formatter. – GhostCat Oct 30 '16 at 14:25
-
Oh, whoops. I had tried searching, but I guess I wasn't thorough enough. – Redempt Oct 30 '16 at 14:51
-
Thats fine. At least you understand the message you got here; and this not something that happens all the time. – GhostCat Oct 30 '16 at 14:55