使用JavaScript设置货币格式 [英] Format currency using javascript
问题描述
脚本以x.xxxx格式返回诸如0.0580的数字,或者以(x)表示剩余的X个单位。
a script returns either a number like 0.0580 so in x.xxxx format or a (x) for X units left.
我想格式化数字0.0580,返回 5.8美分或返回剩余的 x个单位。
I want to format the number 0.0580 and return 5.8 cent or return x units left.
有什么想法可以在javascript中实现吗?尤其是如何格式化x.xxxx?
Any ideas how to do that in javascript? Especially how do I format the x.xxxx?
如果第一个x不为0,我想返回例如1.75 $。
In case the first x is not 0 I want to return e.g. 1.75$.
推荐答案
MS为jquery编写了一个不错的插件。如果您要进行本地化,它特别有用。随便看看吧
MS has written a nice plugin for jquery. it's especially useful if you're localizing. Give it a go:
http://weblogs.asp.net/scottgu/archive/2010/06/10/jquery-globalization-plugin-from-microsoft.aspx
我不确定这是否可以在jquery之外使用...
I'm not sure if this can be used outside of jquery...
这篇关于使用JavaScript设置货币格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!