You are viewing a single comment's thread. Return to all 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)); }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Java Currency Formatter
You are viewing a single comment's thread. Return to all 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();
}