Search code examples
androidcurrencynumber-formattingcurrency-formattingnumberformatter

How do you get Indonesian Rupiah currency formater with `getCurrencyInstance` in Android? What about other locales such as Albanian Lek?


Basically, I want to format a string number into an appropriate looking local format. For example, "15000" into looking more or less like my locale currency format. i.e "Rp.15.000"


Solution

  • Basically, the problem arises since your Locale constant is not readily available. That is, there is no such thing as Locale.INDONESIAN, or Locale.ALBANIAN, or Locale.LATVIAN.

    TL;DR for Indonesian Rupiah format:

    Locale myIndonesianLocale = new Locale("in", "ID");
    NumberFormat formater = NumberFormat.getCurrencyInstance(myIndonesianLocale);
    

    That's for Indonesian locale, what about other locales?

    Go to: https://www.oracle.com/java/technologies/javase/jdk8-jre8-suported-locales.html (please pay attention to Language Tag).

    For Albanian locale pair: sq-AL: Locale myAlbanianLocale = new Locale("sq", "AL");

    For Latvian locale pair: lv-LV Locale myAlbanianLocale = new Locale("lv", "LV");

    And so on.