In node. js, You Can format a number to add a kilobytes of characters.
Processing method separated by commas (,)
Regular Expression mode:
Copy codeThe Code is as follows:
"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 str = '1970. 100'. replace (/(? = (?! ^ )(? : \ D {3}) + (? : \. | $) (\ D {3} (\. \ d + $ )?) /G, ', $1 ');
Console. log (str)
'123'. replace (/\ B (? = (\ D {3}) + $)/g ,',')
Loop Search Method
Copy codeThe Code is as follows:
Function formatNumber (value ){
Value = value. toString ();
If (value. length <= 3 ){
Return value;
} Else {
Return formatNumber (value. substr (0, value. length-3) + ',' + value. substr (value. length-3 );
}
}
ToLocaleString function:
Copy codeThe Code is as follows:
15000000 .. toLocaleString ();