I want to get the currency format of India, so I need a Locale
object for India. But there exists only few a countries that have a Locale
constant (a static final Locale
), and India is not one of them.
To get the currency symbols for the US and UK, I can do the following:
public void displayCurrencySymbols() {
Currency currency = Currency.getInstance(Locale.US);
System.out.println("United States: " + currency.getSymbol());
currency = Currency.getInstance(Locale.UK);
System.out.println("United Kingdom: " + currency.getSymbol());
}
That uses the constants Locale.US
and Locale.UK
. If i want to get the Indian currency format, what can I do?
The getSymbol() method is used to get the symbol of a given currency for the default DISPLAY locale. For example, for the US Dollar, the symbol is "$" if the default locale is the US, while for other locales it may be "US$". If no symbol can be determined, the ISO 4217 currency code is returned.
format(amount); System. out. println(moneyString); The output will be Rs.
The Java Locale class object represents a specific geographic, cultural, or political region. It is a mechanism to for identifying objects, not a container for the objects themselves. A Locale object logically consists of the fields like languages, script, country, variant, extensions.
According to the JDK release notes, you have locale codes hi_IN
(Hindi) and en_IN
(English).
System.out.println(Currency.getInstance(new Locale("hi", "IN")).getSymbol());
heres is simple thing u can do ,
float amount = 100000;
NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
String moneyString = formatter.format(amount);
System.out.println(moneyString);
The output will be , Rs.100,000.00 .
We have to manually create locale for India
Locale IND = new Locale("en", "IN");
NumberFormat india = NumberFormat.getCurrencyInstance(IND);
int money = 3456
System.out.print(india.format(money));
Output - Rs. 3,456
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With