DecimalFormat
uses ','
as the default grouping separator character.
What is the correct way to tell DecimalFormat that we don't want any grouping separator character? I currently use symbols.setGroupingSeparator('\0'), and it seems to work, but it looks ugly.
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator('\0');
DecimalFormat df = new DecimalFormat();
df.setDecimalFormatSymbols(symbols);
ParsePosition pp = new ParsePosition(0);
Number result = df.parse("44,000.0", pp); // this should fail, as I don't want any grouping separatator char.
if (pp.getIndex() != input.length())
throw new Exception("invalid number: " + input, 0);
What is the correct way to tell DecimalFormat that we don't want any grouping separator char?
Turn off grouping by calling setGroupingUsed
:
df.setGroupingUsed(false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With