jQuery 将javascript数字转换为货币格式但没有“$”或任何货币符号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17563677/
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 javascript number to currency format but without "$" or any currency symbol
提问by Ancient
I want to convert my javascript into currency number but with any currency symbol
我想将我的 javascript 转换为货币编号,但可以使用任何货币符号
Suppose this is my number
假设这是我的号码
var number = 43434;
the result should be like this
结果应该是这样的
43,434
and not this
而不是这个
,434
Thanks in advance
提前致谢
回答by mishik
Using one regex /(\d)(?=(\d{3})+(?!\d))/g
:
使用一个正则表达式/(\d)(?=(\d{3})+(?!\d))/g
:
"1234255364".replace(/(\d)(?=(\d{3})+(?!\d))/g, ",");
"1,234,255,364"
To achieve this with an integer you can use +""
trick:
要使用整数实现此目的,您可以使用+""
技巧:
var number = 43434;
(number + "").replace(/(\d)(?=(\d{3})+(?!\d))/g, ","); // 43,434