We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);doublepayment=scanner.nextDouble();scanner.close();NumberFormatusd=NumberFormat.getCurrencyInstance(Locale.US);System.out.println("US format = "+usd.format(payment));NumberFormatinr=NumberFormat.getCurrencyInstance(newLocale("en","in"));System.out.println("India format = "+inr.format(payment));}}
She means a built-in locale like Locale.US - such a locale is so commonly used that it warrants being built-in. There are locales, however, for virtually every country, they just aren't all accessed in a 'built-in' way.
I solved it in a similar way, expect for using printf() instead. I was suprised to find to out that there isn't any field for India baked into Java's Locale class unlike Locale.US and Locale.CHINA, etc. Oh, well...
Java Currency Formatter
You are viewing a single comment's thread. Return to all comments →
Am I misunderstanding how Locales work? I wasn't able to find a locale for india, and had to construct one using:
for the US, I was able to just use
My solution:
I couldn't solve it either. I used:
and got a funny looking character instead of "Rs":
Works correctly and formats the currency as need, I just feel like India would have a built-in locale, so I'm wondering if I'm just overlooking it.
India does not have a built-in Locale; what you did was correct.
when India doesn't have Locale, how is it interpreting india as "RS." ? I am confused!!
I'm struggling with the same thing. Did you ever find an answer here?
She means a built-in locale like
Locale.US
- such a locale is so commonly used that it warrants being built-in. There are locales, however, for virtually every country, they just aren't all accessed in a 'built-in' way.Just change the LowerCase "in" to UpperCase. It'll Work.
The Locale class has 3 constructors, (String language), (String language, String country), (String language, String country, String variant)
Since you only provided 1 string it called the (String language) constructor, which is why the symbol is incorrect
says cannot find the variable for India. Please help.
(new Locale("en","IN"))
That should fix the symbol
I solved it in a similar way, expect for using printf() instead. I was suprised to find to out that there isn't any field for India baked into Java's Locale class unlike Locale.US and Locale.CHINA, etc. Oh, well...