yhkn.net
当前位置:首页 >> js去掉数字千位分隔符 >>

js去掉数字千位分隔符

function ce(num) {return num && (num.toString().indexOf('.') != -1 ? num.toString().replace(/(\d)(?=(\d{3})+\.)/g,function($0, $1) {return $1 + ",";}) : num.toString().replace(/(\d)(?=(\d{3}))/g, function($0, $1) { return $1 + ...

使用下面给出的函数可实现千分符支持正负数: function comma(num) { var source = String(num).split(".");//按小数点分成2部分 source[0] = source[0].replace(new RegExp('(\\d)(?=(\\d{3})+$)','ig'),"$1,");//只将整数部分进行都好分割 ret...

split('xxx')以后就没了,变成了数组。或者replace(new RegExp('xxx',g),'')替换掉

menufunction format (num, fixed) { return num.toFixed (fixed).replace (/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,'); } console.log (format (1.566, 2)); console.info (format (1.56, 2)); console.error (format (1234.566, 2)); console....

方法1:(123456789.2333).toLocaleString('en-US');方法2:function format(input) { var n = parseFloat(input).toFixed(2); var re = /(\d{1,3})(?=(\d{3})+(?:\.))/g; return n.replace(re, "$1,");}format(123456789.2333)

只针对千分符 /^(-)?\d{1,3}(,\d{3})*(.\d+)?$/.test("-123,123.123");

网站首页 | 网站地图
All rights reserved Powered by www.yhkn.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com