The problem is that you are using a static method NumberFormat.getCurrencyInstance() that works that way:

public final static NumberFormat getCurrencyInstance() {
    return getInstance(Locale.getDefault(Locale.Category.FORMAT), CURRENCYSTYLE);
}

As you can see, it returns a NumberFormat object with a default Locale, not the Locale you are setting. That means it depends on user device settings.


So, instead of calling format on that statically returned instance with default Locale:

nf.getCurrencyInstance().format(parsed / 100);

which is effectively the same as:

NumberFormat.getCurrencyInstance().format(parsed / 100);

Use your instance with Locale that you've set:

final NumberFormat nf = NumberFormat.getInstance(Locale.US);
String formatted = nf.format(parsed / 100);
Answer from mkierc on Stack Overflow
Top answer
1 of 6
36

You can try some like this:

public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Utils.getCurrencySymbol(Currency.getInstance(Locale.US).getCurrencyCode());
        Utils.getCurrencySymbol(Currency.getInstance(Locale.JAPAN).getCurrencyCode());
        Utils.getCurrencySymbol(Currency.getInstance(Locale.UK).getCurrencyCode());

        //for your case that you want to get Euro symbol because France are with Euro symnol    
        Utils.getCurrencySymbol(Currency.getInstance(Locale.FRANCE).getCurrencyCode());
        //you can get symbol also if you write string of your desired currency
        Utils.getCurrencySymbol("INR");


    }


    static class Utils {
        public static SortedMap<Currency, Locale> currencyLocaleMap;

        static {
            currencyLocaleMap = new TreeMap<Currency, Locale>(new Comparator<Currency>() {
                public int compare(Currency c1, Currency c2) {
                    return c1.getCurrencyCode().compareTo(c2.getCurrencyCode());
                }
            });
            for (Locale locale : Locale.getAvailableLocales()) {
                try {
                    Currency currency = Currency.getInstance(locale);
                    currencyLocaleMap.put(currency, locale);
                } catch (Exception e) {
                }
            }
        }


        public static String getCurrencySymbol(String currencyCode) {
            Currency currency = Currency.getInstance(currencyCode);
            System.out.println(currencyCode + ":-" + currency.getSymbol(currencyLocaleMap.get(currency)));
            return currency.getSymbol(currencyLocaleMap.get(currency));
        }

    }
}
2 of 6
24

Currency symbol depends on location. The same $ sign means different currencies in US and Australia. So, to get the correct symbol you have to provide the Locale instance. Otherwise, a default locale will be applied, which will result in different values for different devices.

    Locale uk = new Locale("en", "GB");
    Currency pound = Currency.getInstance("GBP");
    pound.getSymbol(uk);
🌐
GitHub
gist.github.com › bkromhout › 5735475
Currency Utils: A class used on android to parse Locale-formatted currency strings to long values for the purpose of storing in a database, and parsing long currency values to locale-formatted strings. Note that this class does not care about exchange rates and does not attempt to do currency conversions. · GitHub
Currency Utils: A class used on android to parse Locale-formatted currency strings to long values for the purpose of storing in a database, and parsing long currency values to locale-formatted strings. Note that this class does not care about exchange rates and does not attempt to do currency conversions.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-use-getcurrencyinstance-method-in-android
How to Use getCurrencyInstance Method in Android? - GeeksforGeeks
August 30, 2021 - { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } fun showValue(view: View) { // variable editText to get the id of editText val editText: EditText = findViewById(R.id.editText) // we've id in editText variable, convert it into Int val value: String = editText.text.toString() // get the currency of local system val currency: Currency = Currency.getInstance(Locale.getDefault()) // store the currency sign in symbol variable val symbol: String = currency.symbol val message = "$symbol$value" // now again find the id of output textView val textView: TextView = findViewBy
🌐
GitHub
github.com › jakeaaron › MultiCurrencyFormatter
GitHub - jakeaaron/MultiCurrencyFormatter: 💸 A small Android library that dynamically reformats user input (from an EditText) for displaying currency values in any locale or currency.
A small Android library that dynamically reformats user input (from an EditText) for displaying currency values in any locale or currency. Java's DecimalFormat is used for formatting the numbers derived from user input.
Author   jakeaaron
🌐
Medium
medium.com › @nabeel.ahamed5 › how-to-format-currency-in-edittext-1e4f205e8128
Android: How to format currency in EditText | by Nabeel Ahamed | Medium
February 26, 2022 - attach the currencyTextWatcher inside the init method. init { addTextChangedListener(textWatcher) } Add a method to get the number without the formatting · fun getNumberText(): String { return text.toString().replace(",", "") } And also please make sure when using that the inputType must be number or numberDecimal or else it will crash because it can’t format text other than numbers. Full code: Android ·
🌐
Android Developers
developer.android.com › api reference › numberformat
NumberFormat | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
Find elsewhere
🌐
Speakman
speakman.net.nz › blog › 2013 › 10 › 21 › android-currency-localisation-hell
Android Currency Localisation Hell - Adam Speakman
It turns out that for versions of Android 4.0.3 and down, the currency format (the NumberFormat.getCurrencyInstance(locale); formatter) does not work correctly for locales that have only single units in their currency. If you check out the sample project you can see that for the Japanese Yen and the Chilean Peso, both of which have only single units, earlier versions of Android will format these with decimal places, where as 4.1 and up does not. But wait, there’s still more. Different locales also return different versions of the same symbol.
Top answer
1 of 2
20

Different currencies can also place the currency symbol before or after the string, or have a different number of decimal places (if any). It is not really clear from your question how you want to handle those cases, but assuming you want to preserve those differences, try this.

Instead of just swapping in the currency symbol into your local number format, you could start with the foreign format and substitute the decimal format symbols with your local version. Those also include the currency, so you have to swap that back (don't worry, it's a copy).

public static NumberFormat localStyleForeignFormat(Locale locale) {
    NumberFormat format = NumberFormat.getCurrencyInstance(locale);
    if (format instanceof DecimalFormat) {
        DecimalFormat df = (DecimalFormat) format;
        // use local/default decimal symbols with original currency symbol
        DecimalFormatSymbols dfs = new DecimalFormat().getDecimalFormatSymbols();
        dfs.setCurrency(df.getCurrency());
        df.setDecimalFormatSymbols(dfs);
    }
    return format;
}

This way, you also retain the correct positioning of the currency symbol and the number of decimal places. Some examples, for default-Locale Locale.UK

en_GB   £500,000.00     £500,000.00
fr_FR   500 000,00 €    500,000.00 €
it_IT   € 500.000,00    € 500,000.00
ja_JP   ¥500,000       JPY500,000
hi_IN   रू ५००,०००.००    INR 500,000.00

If you also want to preserve the foreign currency symbol, instead of the local equivalent, use

localDfs.setCurrencySymbol(df.getCurrency().getSymbol(locale));
2 of 2
7

You can specify the currency symbol on the NumberFormat with the setCurrency method.

Then simply use the Locale.UK to have the proper grouping separator displayed.

format.setCurrency(Currency.getInstance("EUR"));

Note that for a better handling of the grouping/decimal separator you might want to use a DecimalFormat instead.

DecimalFormatSymbols custom=new DecimalFormatSymbols();
custom.setDecimalSeparator('.');
custom.setGroupingSeparator(',');
DecimalFormat format = DecimalFormat.getInstance();
format.setDecimalFormatSymbols(custom);
format.setCurrency(Currency.getInstance("EUR"));

Then specify the correct pattern, example "€ ###,###.00".

🌐
Medium
medium.com › @jacobaallenwood › android-multicurrencyformatter-c04fd7890cb8
Android MultiCurrencyFormatter - by Jacob Allenwood
August 8, 2021 - By default, the MultiCurrencyFormatter uses the default locale associated with the device to parse and format values. The locale dictates the Currency value, which then dictates the currency symbol. This means that in most cases, changing the locale will end up doing the correct thing in relation to the Currency and symbol.
🌐
Android Developers
developer.android.com › api reference › currency
Currency | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Microsoft Support
support.microsoft.com › en-us › office › format-numbers-as-currency-in-excel-for-android-tablet-8d3b62bd-a244-4294-9e62-891f676af52a
Format numbers as currency in Excel for Android tablet - Microsoft Support
... If you want to format numbers as currency, apply either the Currency or Accounting number format to the cells. The number formatting options are available on the Home tab, in the Number Format group. ... Select the cells you want to format. On the Home tab, tap Number Format. Tap Currency ...
🌐
Stack Exchange
android.stackexchange.com › questions › 41801 › how-do-i-change-my-device-locale-default-currency-symbol-on-3-x-and-higher
4.0 ice cream sandwich - How do I change my device locale (default currency symbol) on 3.x and higher? - Android Enthusiasts Stack Exchange
I want to change my device Locale because some of my apps use my default Locale to determine what currency symbol to use when formatting money values. In Android 2.x, I'd just go to the main Settings -> Language and Keyboard Settings -> Locale but I can't find anything like that in my settings for 3.x or 4.x. Any help is appreciated. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags.
🌐
Code Redirect
coderedirect.com › questions › 765682 › android-currency-symbol-ordering
[Solved] Java Android currency symbol ordering - Code Redirect
In Canada, it's reasonably common to see English speakers use the format $50.00, whereas French-Canadians may use 50,00 $. ... https://ux.stackexchange.com/questions/22574/where-to-place-currency-symbol-when-localizing-and-what-to-do-with-odd-symbols