Java:基于ISO 4217货币cod的货币符号 [英] Java: Currency symbol based on ISO 4217 currency cod
问题描述
在程序下面打印给定ISO 4217货币代码的货币符号。
Below program prints the Currency symbol given the ISO 4217 currency code.
import java.util.*;
public class Currency{
public static void main(String args[]) {
Currency myInstance = Currency.getInstance(args[0]);
System.out.println(myInstance.getSymbol());
}
}
问题:工作正常当字符串USD输入时。对于像EUR这样的其他输入,只需返回货币代码。
Problem: Works fine when the string USD is input. For other inputs like EUR just return the Currency Code.
示例输入,来自程序的输出:
Sample input , ouput from the program:
input: java Currency USD
output: $
input: java Currency EUR
output: EUR -> I expect the symbol of Euro here
推荐答案
Currency.getSymbol()
返回相对于默认区域设置的货币符号。
Currency.getSymbol()
returns the currency symbol relative to the default locale.
获取此货币的符号默认语言环境。例如,对于美元,如果默认区域设置是美国,则符号为
$
,而对于其他区域设置,它可能是US $
。如果无法确定符号,则返回ISO 4217货币代码。
Gets the symbol of this currency for the default locale. For example, for the US Dollar, the symbol is
"$"
if the default locale is the US, while for other locales it may be"US$"
. If no symbol can be determined, the ISO 4217 currency code is returned.
使用 Currency.getSymbol(区域设置区域设置)
如果您想要符号对于不同的区域设置。
Use Currency.getSymbol(Locale locale)
if you want the symbol for a different locale.
System.out.println(
Currency.getInstance("USD").getSymbol(Locale.US)
);
// prints $
System.out.println(
Currency.getInstance("USD").getSymbol(Locale.FRANCE)
);
// prints USD
System.out.println(
Currency.getInstance("EUR").getSymbol(Locale.US)
);
// prints EUR
System.out.println(
Currency.getInstance("EUR").getSymbol(Locale.FRANCE)
);
// prints €
(另见ideone.com )。
这篇关于Java:基于ISO 4217货币cod的货币符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!