The project encountered a demand, to the Chinese-style display of Arabic numerals to the European style, that is, each three-bit display, separated by commas, such as 12345678 to 12,345,678 of the display mode, the following is the specific JavaScript code implementation:
var ivalue = 20002365879; The number to convert
var svalue = ivalue+ ';
var avalue = new Array ();
var inum = svalue.length%3;
var Aresult; Convert result
var index = 0;
if (svalue.length<=3) {
console.log (svalue);
} else{
if (inum = = 0) {for
(var i=0; i<svalue.length; i=i+3) {
Avalue[index] = svalue[i]+ ' +svalue[i+1]+ ' +svalue[i+2];
index++
}
} else if (inum = = 1) {
avalue[0] = svalue[0];
index = 1;
for (var i=1 i<svalue.length; i=i+3) {
Avalue[index] = svalue[i]+ ' +svalue[i+1]+ ' +svalue[i+2];
index++
}
} else if (inum = = 2) {
avalue[0] = svalue[0]+ ' +svalue[1];
index = 1;
for (var i=2 i<svalue.length; i=i+3) {
Avalue[index] = svalue[i]+ ' +svalue[i+1]+ ' +svalue[i+2];
index++
}
}
Aresult = Avalue.join (', ');
Console.log (Aresult.tostring ());//Output 20,002,365,879
}
The above JavaScript to convert the Chinese digital format to the European digital format is a simple example of the small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.