Tech 5. Apr. 2006

Localized price formats in Java

A while ago I got the requirement to internationalise an application for creating and organising offers. As I found out how complex the formatting of dates and numbers is, if you are dealing with different countries and languages, I was quite happy that there is something like Java Locale.

So I realized that it seems to be common to write out a price in Euro with a Euro-Sign within the European Union and with EUR instead outside Europe and the similar with US-Dollar. Furthermore the position of the currency sign, the separator character for fractions, the space (or no space) between sign and value and the number of fraction digits are quite different per country or language … I was a kind of fascinated about all that details. All for all that you can easily use the Locale in combination with Currency and CurrencyFormat.

Perfect - I thought till today. So how should we deal with a Japanese locale, which should format and display prices in Euro? Well, probably use the instance of CurrencyFormat with an ISO sign, which allows using an individual currency. Wrong! The Euro-price with the Japanese locale is rounded to full numbers without fraction digits - but with by showing EUR as currency. So there is no way around, as setting the currency, the minimum fraction digits and the maximum fraction digits of the CurrencyFormat instance manually by using the default values of the used currency.

Now it works fine. The price is shown in the right currency, the format of the price value depends on the currency and the position of the sign, the space and the separator character are dependent on the used locale.

A while ago I got the requirement to internationalise an application for creating and organising offers. As I found out how complex the formatting of dates and numbers is, if you are dealing with different countries and languages, I was quite happy that there is something like Java Locale.

So I realized that it seems to be common to write out a price in Euro with a Euro-Sign within the European Union and with EUR instead outside Europe and the similar with US-Dollar. Furthermore the position of the currency sign, the separator character for fractions, the space (or no space) between sign and value and the number of fraction digits are quite different per country or language … I was a kind of fascinated about all that details. All for all that you can easily use the Locale in combination with Currency and CurrencyFormat.

Perfect - I thought till today. So how should we deal with a Japanese locale, which should format and display prices in Euro? Well, probably use the instance of CurrencyFormat with an ISO sign, which allows using an individual currency. Wrong! The Euro-price with the Japanese locale is rounded to full numbers without fraction digits - but with by showing EUR as currency. So there is no way around, as setting the currency, the minimum fraction digits and the maximum fraction digits of the CurrencyFormat instance manually by using the default values of the used currency.

Now it works fine. The price is shown in the right currency, the format of the price value depends on the currency and the position of the sign, the space and the separator character are dependent on the used locale.