Java Currency Formatter

  • + 0 comments

    JAVA 15 currently does not work

    I thought I was going insane, I tried so many diffrent ways that "looked" correct but none worked until i gave up and looked in the comments.

    This is the code i wrote (slightly more cleaned up) that didnt work on the JAVA 15 version. Change to 7 or 8.

        
        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 sc = new Scanner(System.in);
            
            double munny = sc.nextDouble();
            
            NumberFormat US = NumberFormat.getCurrencyInstance();
            
            US.setCurrency(Currency.getInstance(Locale.US));
            DecimalFormat dfIndia = new DecimalFormat("#,###.00");
            
            NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
            NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
            
            
            System.out.println("US: "+US.format(munny));
            System.out.println("India: Rs."+ dfIndia.format(munny));
            System.out.println("China: "+ china.format(munny));
            System.out.println("France: "+france.format(munny));
            
            sc.close();
        }
    }