Format currency in language, regardless of country

I want to format the amount of money (in euros) in the user's language in Java, regardless of the country in which the user is located:

final NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(loc);
currencyFormat.setCurrency(EUR);
currencyFormat.format(new BigDecimal("1.99"));

However, the output for different input locales ( loc) is as follows:

  • nl_NL: € 1,99
  • nl_BE: 1,99 €
  • nl_DE: EUR 1,99
  • nl ( new Locale("nl")):EUR 1,99

So, I have two problems

  • The result depends on the country, and not on the language (like the first 2nd show), but for me it does not matter. My game can be played, for example, in Dutch, traveling around Africa.
  • When using a language standard without a country or a country that does not correspond to the language (second 2), the currency symbol is not printed.

, , nl_DE , , .

+1
4

, :

  • , . nl_NL, nl_BE, fr_FR. . .
  • , . NL, FR, TR. . IP-, .
+1

, , . , , , , . - , , - , 9.999,99, 9999.99, () . , , , - , , (, , ).

.

+1

, , , -, . , , :

  • , , , , , , .
  • , .
  • ( , , ).

, . - - , , . - , Locales Accept-Language HTTP ( , ). "" , , , :

Locale locale = request.getLocale(); // the most acceptable Locale using Servlet API
String language = locale.getLanguage(); // gets language code
String country = locale.getCountry(); // gets country code

, Resource Bundles, Locales (.. zh_CN, zh_TW), ( , ). - .

, , . , . , , , Geolocation ...

, - ...?

+1

Your payment methods should not be tied to the language, they should be tied to what you need for the payment processing system. Then you should display this value in accordance with the customs of the selected region.

0
source

All Articles