如何将阿拉伯数字每三位一逗号分隔,如:15000000转化为15,000,000
2024-08-03 15:27:14 226人阅读
如何将阿拉伯数字每三位一逗号分隔,如:15000000转化为15,000,000
"15000000" .split( "" ).reverse().join( "" ).replace(/(\d{3})/g, "$1," ).split( "" ).reverse().join( "" ); |
"115000000" .split( "" ).reverse().join( "" ).replace(/(\d{3})(?=[^$])/g, "$1," ).split( "" ).reverse().join( "" ); |
var cutStr = function (str) |
var newStr= new Array(str.length+ parseInt(str.length/3)); |
newStr[newStr.length-1]=str[str.length-1]; |
var currentIndex=str.length-1; |
for ( var i = newStr.length-1;i >= 0;i--) |
if ((newStr.length-i)%4==0) |
newStr[i]=str[currentIndex--]; |
console.log(cutStr(num)); |
for ( var i=str.length-1; i>=0; i--){ |
console.log(cutStr(num)); |
var aaa = num.toString(); |
var arr1 = aaa.split( "" ); |
for ( var i = 0; i < arr1.length;) { |
for (j = 0; j < 3; j++) { |
if (j == 2 && i < arr1.length) { |
‘1500000000000‘ .replace(/\B(?=(\d{3})+$)/g, ‘,‘ ) |
function formatNumber(value) { |
value = http://www.mamicode.com/value.toString(); |
return formatNumber(value.substr(0, value.length - 3)) + ‘,‘ + value.substr(value.length - 3); |
console.log(formatNumber(12345678)) |
var str = ‘123123211312.333123‘ .replace(/(?=(?!^)(?:\d{3})+(?:\.|$))(\d{3}(\.\d+$)?)/g, ‘,$1‘ ); |
如何将阿拉伯数字每三位一逗号分隔,如:15000000转化为15,000,000
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉:
投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。