jQuery 将货币名称转换为货币符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19373860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert currency names to currency symbol
提问by richa_pandey
I need quick solution to convert currency names to currency symbols.
我需要快速解决方案将货币名称转换为货币符号。
Like I have GBP which I want to convert into Pound symbol through small javascript/jquery code. Data is totally dynamic.
就像我有英镑一样,我想通过小的 javascript/jquery 代码将其转换为英镑符号。数据是完全动态的。
I can't use any plugin like currenyformat
.
我不能使用任何插件,如currenyformat
.
Looking for quick help.
寻求快速帮助。
回答by Vin.AI
Do this:
做这个:
var currency_symbols = {
'USD': '$', // US Dollar
'EUR': '', // Euro
'CRC': '?', // Costa Rican Colón
'GBP': '£', // British Pound Sterling
'ILS': '?', // Israeli New Sheqel
'INR': '?', // Indian Rupee
'JPY': '¥', // Japanese Yen
'KRW': '?', // South Korean Won
'NGN': '?', // Nigerian Naira
'PHP': '?', // Philippine Peso
'PLN': 'z?', // Polish Zloty
'PYG': '?', // Paraguayan Guarani
'THB': '?', // Thai Baht
'UAH': '?', // Ukrainian Hryvnia
'VND': '?', // Vietnamese Dong
};
var currency_name = 'INR';
if(currency_symbols[currency_name]!==undefined) {
alert(currency_symbols[currency_name]);
}
NOTE: Not every currency has symbol. Only listed above currencies have real symbol.
注意:并非每种货币都有符号。只有上面列出的货币才有真正的符号。
回答by Jonathan de M.
You could use a JSON to match the code with the symbol, here is a JSON to do so: https://gist.github.com/Fluidbyte/2973986
您可以使用 JSON 将代码与符号匹配,这是一个 JSON:https: //gist.github.com/Fluidbyte/2973986
var data = {
// the json I gave you above
}
var code = $('input').val();
// the input which contains the code
$.each(data, function(i, v){
if(i === code){
$('#result').html(v.symbol);
// #result is an empty tag which receive the symbol
return;
}
});