pretzels04
pretzels04

Reputation: 33

Currency Locale- How to get the locale for the different countries

public  double showinbrl(double amount, double rate) {
        double amountinbrl = amount * rate; 
        NumberFormat brl = NumberFormat.getCurrencyInstance(Locale.BRAZIL); 
        brl.format(amountinbrl);
        return amountinbrl;
    }

how to get the locale for the different countries... i cant find locale for brazil..

Upvotes: 0

Views: 1005

Answers (2)

Giulio
Giulio

Reputation: 23

UPDATING 2023 (KOTLIN):

When I tried to use "Locale.forLanguageTag("pt_BR")" it didn't work for me, it's not formatting correctly and it's showing an unknown character:

unknown character appearing when using Locale.forLanguageTag("pt_BR")

So I googled and used the following code and it worked:

val brl = NumberFormat.getCurrencyInstance(Locale("pt", "BR"))

Brazil currency character displayed correctly by using Locale("pt", "BR")

Upvotes: 1

Nikhil Talreja
Nikhil Talreja

Reputation: 2774

Try this:

NumberFormat brl = NumberFormat.getCurrencyInstance(Locale.forLanguageTag("pt_BR"));

Upvotes: 2

Related Questions