JavaScript 数字千元符方法
作者:互联网
// normal 参数是币种 币种等于 JPY 【日元】不显示千元符 默认显示千元符 function toThousands(num = 0, currency = 'normal', point = 2) { let newNum = String(num) var reg = new RegExp(',', 'g') if (newNum.indexOf(',') !== -1) { newNum = newNum.replace(reg, '') } let zero = '.00' if (newNum === 'null') { newNum = 0 } else { newNum = Number(newNum) } if (currency === 'JPY') zero = '' var [sInt, sFloat] = (Number.isInteger(newNum) ? `${newNum}` : newNum.toFixed(point)).split('.') sInt = sInt.replace(/\d(?=(\d{3})+$)/g, '$&,') return sFloat ? `${sInt}.${sFloat}` : `${sInt}` + `${zero}` }
标签:数字,point,千元,sInt,JavaScript,sFloat,zero,newNum 来源: https://www.cnblogs.com/qfcddl/p/14142617.html