Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DecimalFormat.applyPattern("#.##0,00") throwing an exception

For the code:

DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(locale);
df.applyPattern("#.##0,00");

And it throws an IllegalArgumentException with a message of Malformed pattern "#.##0,00"

What is wrong with this?

Edit: I want to use the . as a thousands separator and , as the decimal. I know that's ass-backwards but have a case where that's the format they want.

like image 963
David Thielen Avatar asked Dec 24 '22 20:12

David Thielen


1 Answers

You need to use the pattern "#,##0.##" to indicate where you want to decimal separator and the thousand seperator. The Locale you use when using this DecimalFormat will then determine if the decimal separator is a . or , -- the pattern should NOT be changed.

If you are not getting the correct separators, you will need to use a different Locale.

like image 105
john16384 Avatar answered Dec 26 '22 10:12

john16384