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(''), and it seems to work,
but it looks ugly.
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator('');
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…