java currency formatter hackerrank solution

Solutions on MaxInterview for java currency formatter hackerrank solution by the best coders in the world

showing results for - "java currency formatter hackerrank solution"
Jesús
15 Mar 2020
1import java.util.Scanner;
2import java.text.NumberFormat;
3import java.util.Locale;
4
5public class Solution {
6    
7    public static void main(String[] args) {
8        /* Read input */
9        Scanner scanner = new Scanner(System.in);
10        double payment = scanner.nextDouble();
11        scanner.close();
12
13        /* Create custom Locale for India. 
14          I used the "IANA Language Subtag Registry" to find India's country code */
15        Locale indiaLocale = new Locale("en", "IN");
16
17        /* Create NumberFormats using Locales */
18        NumberFormat us     = NumberFormat.getCurrencyInstance(Locale.US);
19        NumberFormat india  = NumberFormat.getCurrencyInstance(indiaLocale);
20        NumberFormat china  = NumberFormat.getCurrencyInstance(Locale.CHINA);
21        NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
22
23        /* Print output */        
24        System.out.println("US: "     + us.format(payment));
25        System.out.println("India: "  + india.format(payment));
26        System.out.println("China: "  + china.format(payment));
27        System.out.println("France: " + france.format(payment));
28    }
29}