Java Currency Formatter

Sort by

recency

|

817 Discussions

|

  • + 0 comments

    Indian format only worked as expected on the result in java 8

  • + 1 comment

    My code, when run, prints the Chinese yuan with two stikes on Y, while the expected output demands the yuan character with only one strike on Y. Hence, my code is not passing the test case.

    Any suggestions are cited and welcome.

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
    
        Scanner scanner = new Scanner(System.in);
    

    double payment = scanner.nextDouble(); var u = NumberFormat.getCurrencyInstance(Locale.US); var i = NumberFormat.getCurrencyInstance(new Locale("en", "IN")); var c = NumberFormat.getCurrencyInstance(new Locale("zh","CN")); var f = NumberFormat.getCurrencyInstance(Locale.FRANCE); System.out.println("US: "+u.format(payment)); System.out.println("India: "+i.format(payment).replace(i.getCurrency().getSymbol(), "Rs.")); System.out.println("China: "+c.format(payment)); System.out.println("France: "+f.format(payment));

    }
    

    }

  • + 0 comments

    public class Solution {

    public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            double payment = scanner.nextDouble();
            scanner.close();
    
            // Write your code here.
            // us: u
            // India: i
            // China: c
            // France: f
    
            /*
            Configuraciones regionales
            getInstance: solo la cantidad
            getCurrencyInstance: te da el simbolo de la moneda tambien
            */
    
            Locale usLocale = new Locale("en", "US"); 
            Locale indiLocale = new Locale("en", "IN");
            Locale chiLocale = new Locale("zh", "CN");
            Locale frLocale = new Locale("fr", "FR");
    
            NumberFormat usFormat = NumberFormat.getCurrencyInstance(usLocale);
            NumberFormat indiFormat = NumberFormat.getCurrencyInstance(indiLocale);
            NumberFormat chiFormat = NumberFormat.getCurrencyInstance(chiLocale);
            NumberFormat frFormat = NumberFormat.getCurrencyInstance(frLocale);
    
            String us = usFormat.format(payment);
            String india  = indiFormat.format(payment);
            String china = chiFormat.format(payment);
            String france = frFormat.format(payment);
    
            System.out.println("US: " + us);
            System.out.println("India: " + india);
            System.out.println("China: " + china);
            System.out.println("France: " + france);
    }
    

    }

  • + 0 comments

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double payment = scanner.nextDouble();
        scanner.close();
    
        // Write your code here.
         String us = NumberFormat.getCurrencyInstance(Locale.US).format(payment);
    
        Locale INDIA = new Locale("en", "IN");
    
          NumberFormat indiaFormat = NumberFormat.getCurrencyInstance(INDIA);
          String india = indiaFormat.format(payment);
          String indianCurrencySymbol = indiaFormat.getCurrency().getSymbol(INDIA);
          india = india.replace(indianCurrencySymbol, "Rs.");
          String china = NumberFormat.getCurrencyInstance(Locale.CHINA).format(payment);
          String france = NumberFormat.getCurrencyInstance(Locale.FRANCE).format(payment);
        // double us = 
    
        System.out.println("US: " + us);
        System.out.println("India: " + india);
        System.out.println("China: " + china);
        System.out.println("France: " + france);
    }
    

    }

  • + 0 comments

    This code is working

    import java.util.; import java.text.;

    public class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double payment = scanner.nextDouble();
        scanner.close();
    
        // Write your code here.
    
        NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
        NumberFormat india = NumberFormat.getCurrencyInstance(new Locale("en","IN"));
        NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
        NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
    
        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));
    }
    

    }