JS uses regular expressions to add a thousand character to the integer part of a number for every three digits.

Today, I took a front-end written test. The last question is to give a long number. I want you to write a function to return the effect of adding a thousand character to the number

.

eg: input 1234567891.123, and finally output 1234567891.123, ask you how to achieve it.

I came back to check the data and found that it could be done with the zero-width assertion of the regular expression. It was written, but there were two questions that needed to be answered by the boss. I wrote them in the code .

var thousandBitSeparator = function(numStr){
     var b = /(?<=\d)(\d{3})/g;     //1.exp
     return numStr.replace(b, function($1){
          return ","+$1;
     });
}
alert(thousandBitSeparator("1234567891.123"));//1,234,567,891.123 
alert(thousandBitSeparator("12345678912.123"));//1,234,567,8912.123 2.

https://github.com/anran758/F.

try this..

< hr >

reminded by the friends in the comment area.. Fault tolerance is carried out for the decimal point, and the regular only takes the integer part.

  http://regex.zjmainstay.cn/r/.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b41508-ead2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b41508-ead2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?