问题描述
我编写了一个程序,以返回带有某些国家/地区的货币符号的双精度值.为此,我正在使用getCurrencyInstance()
方法来获取特定国家/地区的符号.
I have written a program to return double values with the currency symbols of some countries. For this I am using getCurrencyInstance()
method to get symbol of particular country.
该问题特定于笔记本电脑的 JDK-1.8 ,并且可以在联机编译器上正常运行.我面临的问题是 CHINA 和 FRANCE 的货币符号用'?'表示.但是对于 INDIA 和 US ,会显示正确的符号.
The problem is specific to my laptop's JDK-1.8 and works fine on online compiler.The problem, I am facing is that the currency symbol for CHINA and FRANCE are represented with '?'. But for INDIA and US, correct symbols are shown.
我现在正在解决这个问题.因此,任何线索都将有所帮助.
I am working on this problem for a bit now. Hence, any leads would be helpful.
这是我的代码:
import java.util.Scanner;
import java.text.NumberFormat;
import java.util.Locale;
public class Solution {
public static void main(String[] args) {
/* Read input */
Scanner scanner = new Scanner(System.in);
double payment = scanner.nextDouble();
scanner.close();
/* Create custom Locale for India.
Locale indiaLocale = new Locale("en", "IN");
/* Create NumberFormats using Locales */
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale);
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
/* Print output */
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));
}
}
我的机器上的相应输出是:
The corresponding output on my machine is:
12324.134
US: $12,324.13
India: Rs.12,324.13
China: ?12,324.13
France: 12 324,13 ?
推荐答案
在中国使用此代码.Numberformat类的getCurrency().getSymbol(locale)将返回特定区域的货币符号. System.out.println("China: " + china.getCurrency().getSymbol(Locale.CHINA) + china.format(payment));
for china use this code.Numberformat class's getCurrency().getSymbol(locale) will return currency symbol for particular region. System.out.println("China: " + china.getCurrency().getSymbol(Locale.CHINA) + china.format(payment));
在法国使用此System.out.println("France: " + france.format(payment) + " " + france.getCurrency().getSymbol(Locale.FRANCE));
For France use thisSystem.out.println("France: " + france.format(payment) + " " + france.getCurrency().getSymbol(Locale.FRANCE));
这篇关于NumberFormat.getCurrencyInstance()不返回语言环境中国和法国的货币符号(jdk-1.8)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!