Getting Currency Symbol from Currency Code

爱⌒轻易说出口 提交于 2019-12-12 04:53:31

问题


I want to display a list of currencies that would have the ISO and the currency symbol in brackets i.e. something like USD($) or GBP(£). The list is supposed to be dynamic, so hard-coding it is out of the question because the user gets to choose what kind of currencies they get to see in the list. I've been able to get the ISO values to show up, but I want the symbols too.

Is there a webservice or some class that can convert 'USD' to '$'?


回答1:


$string_variable = "USD 9.99";    

$string_variable = str_replace("USD ", "\$", $string_variable);

echo $string_variable;

will echo $9.99




回答2:


Just to know about currency symbols hitting the webservice each time is not a good idea. It could be possible third party webservice provider can go to server maintenance without informing and in this situation your application will not work.

Its better if you can download the currency symbol against ISO code, create HashMap of it at server start up time and fetch the related value from it.

Below is the link from where you can download the FinalCurrency.xls. https://drive.google.com/file/d/0B5DVIZeIMrCQMGRYT3NFd05CSGM/edit



来源:https://stackoverflow.com/questions/26327699/getting-currency-symbol-from-currency-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!