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.
The tricky part is creating a custom local for India. I had to look up India's country code in the IANA Language Subtag Registry. If anyone had an easier way to find it please let me know.
importjava.util.Scanner;importjava.text.NumberFormat;importjava.util.Locale;publicclassSolution{publicstaticvoidmain(String[]args){/* Read input */Scannerscanner=newScanner(System.in);doublepayment=scanner.nextDouble();scanner.close();/* Create custom Locale for India. I used the "IANA Language Subtag Registry" to find India's country code */LocaleindiaLocale=newLocale("en","IN");/* Create NumberFormats using Locales */NumberFormatus=NumberFormat.getCurrencyInstance(Locale.US);NumberFormatindia=NumberFormat.getCurrencyInstance(indiaLocale);NumberFormatchina=NumberFormat.getCurrencyInstance(Locale.CHINA);NumberFormatfrance=NumberFormat.getCurrencyInstance(Locale.FRANCE);/* Print output */System.out.println("US: "+us.format(payment));System.out.println("India: "+india.format(payment));System.out.println("China: "+china.format(payment));System.out.println("France: "+france.format(payment));}}
Java Currency Formatter
You are viewing a single comment's thread. Return to all comments →
Java solution - passes 100% of test cases
The tricky part is creating a custom local for India. I had to look up India's country code in the IANA Language Subtag Registry. If anyone had an easier way to find it please let me know.
From my HackerRank Java solutions.