JavaScript: Format number/currency w/regards to culture like .NET's String.Format()?

最后都变了- 提交于 2019-12-06 04:50:51

问题


This seems like a problem someone would've already solved in the year 2009, but I can't find a decent JavaScript library that will take a number like:

12345.58

And format it correctly based on a specific culture (ie, "nl-nl") or ISO currency code.

dojo showed promise, but it doesn't include many cultures by default, and actually wasn't working properly in my tests.

I basically want something that is 100% or near-100% equivalent to what .NET does for me, when I run:

String.Format([cultureInfo Object], "{0:N}", myValue) ' for numbers

and

String.Format([cultureInfo Object], "{0:C}", myValue) ' for currency


回答1:


The ASP.NET Ajax framework lets you do this.

Set the EnableScriptGlobalization property on the ScriptManager to true. You can then use the Number.localeFormat function to format numbers.



来源:https://stackoverflow.com/questions/1615869/javascript-format-number-currency-w-regards-to-culture-like-nets-string-forma

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