3

I have a problem. I work with amounts in application, and I need to localize the format. I use the NumberFormat.getCurrencyInstance() of java.util.Locale. By most cases it looks just fine. But the negative numbers are the problem. The predefined format for Dutch nl-NL locale looks like this

€ 200,00-

but according to the standards in the Netherlands, it should be

€ -200,00

The example is NumberFormat.getCurrencyInstance(new Locale("nl", "NL")).format(-200). I don't want to change the format otherwise.

Any ideas?

jaruss
  • 153
  • 1
  • 9

1 Answers1

4

Yes, this explains the problem pretty well (discrepancy between CLDR - used by Java - and official Dutch language recommendation).

To use a different format than the CLDR one you have to define it yourself, using the default format for positive values and a different one for negative numbers:

((DecimalFormat)NumberFormat.getCurrencyInstance(new Locale("NL", "nl"))).applyPattern("¤ #,##0.00;¤ -#").format(-200);

(how you decompose this, where you apply the pattern etc will of course depend on your existing code)

¤ #,##0.00 is the current default Dutch pattern for positive values, ¤ -# is the new pattern for negative values which means "currency symbol first, then a non-breaking space (i.e. \u00a0, not the regular SPC character), then negative symbol, then same format as positive value" (; separates positive value format from negative one in the formatting string).

desseim
  • 7,968
  • 2
  • 24
  • 26