How to format currency for a locale in Java

I am surprised that I am having real problems with how to do this. I think it should be pretty simple. Maybe I'm looking in the wrong place.

Suppose I have the following code:

double amount = 123.45D; //yes, I know that I should be using longs
Locale uk = Locale.UK;
Locale fr = Locale.FR;
Currency euro = Currency.getInstance("EUR");

How do I get instances of NumberFormat that allow me to print the value 123.45 correctly formatted for Locale? those. I want the following for the UK and France respectively:

€123.45
123,45 €

I can not use NumberFormat.getCurrencyInstance(Locale), because the format will format in the UK as Sterling (£). I am looking NumberFormat.getCurrencyInstance(Locale, Currency), but this does not seem to exist.

Any ideas?

+5
source share
1 answer

NumberFormat.setCurrency(), , NumberFormat, NumberFormat.getCurrencyInstance(Locale).

+4

All Articles