将货币名称转换为货币符号

我需要快速解决方案将货币名称转换为货币符号。

就像我有GBP我想通过小的javascript / jquery代码转换成Pound符号。 数据完全是动态的。

我不能使用任何插件,如currenyformat

寻求快速帮助。

做这个:

 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]); } 

注意:并非每种货币都有符号。 只有上面列出的货币才有真实符号。

您可以使用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; } }); 

检查url以将货币名称转换为货币符号。

http://www.josscrowcroft.com/2011/code/format-unformat-money-currency-javascript/

也许

 stringName.replace("GBP","£");