Java Currency Formatter

  • + 4 comments

    My code is working on compter...

    The output I get from HackerRank is:

    US: $12,324.13

    India: Rs.12,324.13

    China: ?12,324.13

    France: 12?324,13 ?

    But I get this in IntelliJ fine... 123.443 US: $123.44 India: ₹ 123.44 China: ï¿¥123.44 France: 123,44 â‚¬

    package com.company; import java.io.; import java.text.; import java.util.*;

    class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close();

        NumberFormat nfU = NumberFormat.getCurrencyInstance(Locale.US);
        NumberFormat nfI = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
        NumberFormat nfC = NumberFormat.getCurrencyInstance(Locale.CHINA);
        NumberFormat nfF = NumberFormat.getCurrencyInstance(Locale.FRANCE);
    
        System.out.println("US: " + nfU.format(payment));
        System.out.println("India: " + nfI.format(payment));
        System.out.println("China: " + nfC.format(payment));
        System.out.println("France: " + nfF.format(payment));
    }
    

    }