JavaScript translates Chinese digital format into a simple example of European digital format _javascript tips

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.