0

Java 11

I'm dealing with Czech karona currency and need to display

50427.1 as 50 427,10 Kč

Tried,

System.out.println(new java.text.DecimalFormat("## ###,00 Kč").format(Double.valueOf("50427.1")));

But its printing as

5,04,27  Kč

How can i make it to display in the correct format?

SyAu
  • 1,651
  • 7
  • 25
  • 47

2 Answers2

2

Specify the locale to use in order to propely format the values

System.out.println(new DecimalFormat("#,###.00 ¤", DecimalFormatSymbols.getInstance(Locale.forLanguageTag("cs-CZ"))).format(50427.1));

will output

50 427,10 Kč
Jonnathan Q
  • 312
  • 1
  • 8
1

You don't need to specify the format; just use the locale's currency formatter:

NumberFormat.getCurrencyInstance(Locale.forLanguageTag("cs-CZ")).format(50427.1)

If you want to include the trailing 0 decimals, you can setMinimumFractionDigits(2).

Ideone Demo

shmosel
  • 49,289
  • 6
  • 73
  • 138