Search code examples
androidformatlocalecurrency

Android select currency


I saw in the forum that others have the same problem, but no one explains how he solved. I have a TextView in my Activity, with a string in currency format

For example, if the user has the phone set to U.S. English language, and yet want to display currency in € or more, how can I do?

Double value_tot = Double.valueOf(totale);
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    String super_totale = formatter.format(value_tot );
    aTotale.setText(super_totale);

Solution

  • You can configure the currency to use in the NumberFormat class, like this:

    NumberFormat nf = NumberFormat.getCurrencyInstance();
    nf.setCurrency(Currency.getInstance("EUR"));
    

    Then nf.format(123.5) will produce "€123.50"