2

I would like to do this: if I have 1234.5678, I would like 1 234.57. I have tried several things, like:

Object theValue = theValues.get(theHeaderName);
DecimalFormatSymbols theSymbols  = new DecimalFormatSymbols();
theSymbols.setGroupingSeparator(' ');
DecimalFormat theFormatter = new DecimalFormat("#.00", theSymbols);
el.text(theFormatter.format(theValue));

But I don't manage to have the rounding and the separator.

ZygD
  • 22,092
  • 39
  • 79
  • 102
Kaki
  • 33
  • 6
  • Have a look at this question http://stackoverflow.com/questions/5323502/how-to-set-thousands-separator-in-java. It deals with separators. – NaN May 13 '15 at 13:43
  • 1
    Just use this as a format - ###,###.00 – Zyga May 13 '15 at 13:44

1 Answers1

2

If you overwrite the standard format with #.00 you have no grouping seperator in your format. For your expected case you have to include the grouping seperator again into your custom format:

DecimalFormat theFormatter = new DecimalFormat("#,###.00", theSymbols);

The pattern definition symbols can be found in the Doc

ceekay
  • 471
  • 3
  • 14