On the type of JS number format

Source: Internet
Author: User

Text: A brief talk on JS number format type

Many people may only know 123,123.456,0xFF and the like number format.
In fact, JS format has a lot of number format types, such as 1., . 1 So, there are . 1e2 such.

Could someone say what format this is?
There's more to it than that.
1           //1
1.2        //1.2
//1200
//1200
1.2e-3   // 0.0012
.12E+2  //12
-.12e-2 //-0.0012

Of course these are just decimal. Let's say octal and hex.
0x00, 0x11, 0xff This format is hexadecimal, their decimal values are 0, 255, respectively.

010, 012 , this is the octal system. ( 0 Here is the number 0, not the letter O)
May have a friend questioned, this is not a decimal, how to say it is octal it?
In fact, this is the octal system, just add a 0 before the decimal.

Of course not all plus 0 is octal.
For example, The real is the decimal, because octal to 8 on the Carry, it is impossible to appear in the.

is not the view of a lot of open, no longer confined to the form of the decimal, and do not have to be afraid of the code that Daniel wrote scared silly.

There might be friends who would say, octal, hex, supporte+-This format?

0x12e3===4835
0x12e+3===305
0x12e-3===299
0x12=== -
Obviously, it's not the result we think about.
In fact0x12e3is becauseeis also a hexadecimal character, the hexadecimal character is0-9Plusa-f, the case does not matter, so0x12e3is a normal hexadecimal number format.
0x12e+3Why not, actually it's just two numbers added,0x12eThe decimal is302Plus3Will get305, so he is an expression, not a mere number.

and 011e2 Such a format is also wrong, and even directly reported grammatical errors.
So the exponential format can only be used in decimal.

Encounter 1e6 in the future not as naïve as IE6 .
And don't be depressed . 5 Why not make a mistake,. 1e1 why equals 1 .

Well, share this little bit of knowledge today, and think about it slowly.

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.