You are viewing a single comment's thread. Return to all comments →
Why this code does not work? Is there any idea? I am thinking might be an system error. Because the output is the same with it should be.
import java.io.; import java.util.; import java.text.NumberFormat; import java.util.Locale; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; public class Solution {
public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double payment = scanner.nextDouble(); scanner.close(); NumberFormat usFormat = NumberFormat.getCurrencyInstance(Locale.US); String us = usFormat.format(payment); Locale indiaLocale = new Locale("en","IN"); NumberFormat indiaFormat = NumberFormat.getCurrencyInstance(indiaLocale); DecimalFormatSymbols dfs = ((DecimalFormat) indiaFormat).getDecimalFormatSymbols(); dfs.setCurrencySymbol("Rs."); ((DecimalFormat) indiaFormat).setDecimalFormatSymbols(dfs); String india = indiaFormat.format(payment); NumberFormat chinaFormat = NumberFormat.getCurrencyInstance(Locale.CHINA); String china = chinaFormat.format(payment); NumberFormat franceFromat = NumberFormat.getCurrencyInstance(Locale.FRANCE); String france = franceFromat.format(payment); System.out.println("US: "+ us); System.out.println("India: " + india); System.out.println("China: "+ china); System.out.println("France: "+ france); }
}
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 →
Why this code does not work? Is there any idea? I am thinking might be an system error. Because the output is the same with it should be.
import java.io.; import java.util.; import java.text.NumberFormat; import java.util.Locale; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; public class Solution {
}