Enhancing regex of thousands separator?

后端 未结 5 1190
长发绾君心
长发绾君心 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:19

    Try this one:

    result = subject.replace(/([0-9]+?)([0-9]{3})(?=.*?\.|$)/mg, "$1,$2");
    

    Test here

提交回复
热议问题