Enhancing regex of thousands separator?

后端 未结 5 1187
长发绾君心
长发绾君心 2021-01-15 03:50

I saw this beautiful script to add thousands separator to js numbers:

function thousandSeparator(n, sep)
{
    var sRegExp = new RegExp(\'(-?[0-9]+)([0-9]{3         


        
5条回答
  •  执念已碎
    2021-01-15 04:02

    How about this one:

    result = "1235423.125".replace(/\B(?=(\d{3})+(?!\d))/g, ',') //1,235,423.125
    

提交回复
热议问题