一.去掉千分位
function removeThousands(num) { var x = num.split(‘,‘); return parseFloat(x.join("")); }
二.添加千分位
function addThousands(num) { var reg = /\d{1,3}(?=(\d{3})+$)/g; if ( num &&num.toString().indexOf(‘.‘) == -1) { return (num + ‘‘).replace(reg, ‘$&,‘); } else { return num.toString().replace(/(\d)(?=(\d{3})+\.)/g, function ($0, $1) { return $1 + ","; }); } }
原文地址:https://www.cnblogs.com/muyeh/p/10999348.html
时间: 2024-10-08 15:46:58