简体   繁体   中英

Query about output in “Currency converting problem in Java”

Everything is Ok, I also get exact output. But when I run it in hackerrank it doesnt show the "sign/symbol" of Chinese & France currency. So it is not accepted.

What should I do now?

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


class Solution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        double amount = scanner.nextDouble();

        Locale indiaLocale = new Locale("en", "IN");


        NumberFormat USA = NumberFormat.getCurrencyInstance(Locale.US);
        NumberFormat CHINA = NumberFormat.getCurrencyInstance(Locale.CHINA);
        NumberFormat INDIA  = NumberFormat.getCurrencyInstance(indiaLocale);
        NumberFormat FRANCE = NumberFormat.getCurrencyInstance(Locale.FRANCE);

        String usa = USA.format(amount);
        String india = INDIA.format(amount);
        String china = CHINA.format(amount);
        String france = FRANCE.format(amount);

        System.out.println("USA: " +usa);
        System.out.println("India: " +india);
        System.out.println("China: " +china);
        System.out.println("France: " +france);

    }
}
        Currency eur = java.util.Currency.getInstance("EUR");
        NumberFormat EUR = NumberFormat.getCurrencyInstance(Locale.FRANCE);
        EUR.setCurrency(eur);
        System.out.println(EUR.format(34));

This should work, assuming you actually want to use CFP and not EUR. You'll have to look up the currency codes for each currency you want.

You need to do something like this:

static public void displayCurrency( Locale currentLocale) {

    Double currencyAmount = new Double(9876543.21);
    Currency currentCurrency = Currency.getInstance(currentLocale);
    NumberFormat currencyFormatter = 
                        NumberFormat.getCurrencyInstance(currentLocale);

    System.out.println( currentLocale.getDisplayName() + ", " +
        currentCurrency.getDisplayName() + ": " +
        currencyFormatter.format(currencyAmount));
}

Look here for more details: https://docs.oracle.com/javase/tutorial/i18n/format/numberFormat.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM