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...

比如分隔符为& arr=str.split('&'); arr.join();

function format (num) { return (num.toFixed(2) + '').replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,');}var num = 12345;alert(format(num));

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....

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