Use a thousands separator (comma) to represent large numbers in a Web page

Source: Internet
Author: User

Do mobile phone page We often encounter numbers, and in the Safari browser these numbers will display the phone number by default, so we use the method of pit to add <meta> tags:

<meta name= "format-detection" content= "Telephone=no" >
The meaning of this tag is that the number is not treated as a phone number, so it's all right. O (∩_∩) O, but if it is a reservation phone, then after adding the label, the order number will become a digital, you can not dial directly so we think of the old number of thousands of characters to distinguish between telephone numbers and numbers

thousand characters

In the west, when representing a large number, will be separated by every 3 bits of the interval, the symbol is a comma, because in Chinese, the 3rd place is "thousand", therefore, the number of the "comma" is also known as the "thousands separator."

The reason for this is that each of the 3-bit separators is related to readings in English, for example: the 987,654,321 reading of English is: nine hundred and eighty-seven billion six hundred and Fifty-four thousand three hundred and twenty-one.

Its key unit of values, such as billion , thousand is exactly where the thousand separators are. It can be seen that this separation is complementary to Western numerical reading methods.

But for Chinese users, this style is rather awkward. Our large value units are mainly "million" and "billion", if the division according to this standard, should be every 4 bits to separate. So, when we first saw the 3-bit numbers, it would be strange that the way they were separated was somewhat out of order.

Is there a solution to that?

Method One:
Method One: Use regular expressions

The syntax is as follows:

String (number). Replace (/(\d) (? = (\d{3}) +$)/g, "$");


String (123456789). Replace (/(\d) (? = (\d{3}) +$)/g, "$");

Method Two:
Method Two: Use toLocaleString()Method

The syntax is as follows:

Number.tolocalestring (' en-us ');


(123456789). toLocaleString (' en-us ');

The result is: 123,456,789

In the Chinese scene, toLocaleString(‘en-US‘) in ‘en-US‘ theory can be the default, that is, directly (123456789).toLocaleString() can also get 123,456,789. However, if your product may be used by overseas users, it is safe to keep it ‘en-US‘ .

In addition, for the previous version of IE Edge, Number.toLocaleString() will automatically fill up two decimal places, if it is not needed, you need to filter out the extra.

Use a thousands separator (comma) to represent large numbers in a Web page

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: 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.