1

I'm trying to convert a float number to a currency string in a similar format returned by SkuDetail's getPrice method, for reference it returns a string like this 1 234,56 Ft

I've tried

    NumberFormat format = NumberFormat.getCurrencyInstance();
    format.setCurrency(Currency.getInstance("HUF"));
    format.format(12345.67)

But it returns HUF1,2345.67

Is there any way to reach similar result to the getPrice method?

kviktor
  • 1,076
  • 1
  • 12
  • 26

1 Answers1

7

If you always want the currency format to match an Americanised expectation, leave the locale as Locale.US. If you want the currency to display in a localised way, leave your implementation as is. The locale controls format of , vs . and Where the currency sign will appear.

   Double number = 1500D;

    // Format currency for Canada locale in Canada locale, 
    // the decimal point symbol is a comma and currency
    // symbol is $.
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.CANADA);
    String currency = format.format(number);
    System.out.println("Currency in Canada : " + currency);

    // Format currency for Germany locale in German locale,
    // the decimal point symbol is a dot and currency symbol
    // is €.
    format = NumberFormat.getCurrencyInstance(Locale.GERMANY);
    currency = format.format(number);
    System.out.println("Currency in Germany: " + currency);

Results

Currency in Canada : $1,500.00
Currency in Germany: 1.500,00 €

Here is another answer Android currency symbol ordering

skryshtafovych
  • 572
  • 4
  • 16