On the type of JS number format

Source: Internet
Author: User
Tags format expression

Many people may only know the number format such as 123,123.456,0xff.
In fact, the JS format there are many types of digital format, such as 1,. 1 such, there are. 1e2.

Someone might say what format it is?
Actually, it's more than that.
1//1
1.2//1.2
1.2e3//1200
1.2e+3//1200
1.2e-3//0.0012
.12e+2//12
-.12e-2//-0.0012

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

01, 07, 010, 012 This is an 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 is octal?
In fact, this is the octal system, but in the decimal before adding a 0 just.

Of course not all plus 0 are octal.
For example, 08, 09 is actually decimal, because octal to 8 on the carry, so it is impossible to appear 08, 09.

is not that the view is open a lot, no longer limited to the decimal form of expression, do not have to fear the code written by Daniel Silly.

Maybe a friend would say, octal, hexadecimal, support e+-this format?

0x12e3 = = 4835
0x12e+3 = = 305
0x12e-3 = = 299
0x12 = = 18
Obviously, it's not the result we think about.
In fact 0x12e3 is because E is also hexadecimal characters, hexadecimal characters are 0-9 plus a-f, the case does not matter, so 0x12e3 is a normal hexadecimal number format.
0x12e+3 Why is not it, in fact, it is only two number added, 0x12e decimal is 302, plus 3 to get 305, so he is an expression, not a simple figure.

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

Later encountered 1e6 don't be naïve as IE6.
And don't be depressed. 5 Why not make a mistake,. 1e1 why is equal to 1.

Well, share a little bit of knowledge today, and think 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.