Home > Web Front-end > JS Tutorial > JavaScript study notes--numeric format type_javascript skills

JavaScript study notes--numeric format type_javascript skills

WBOY
Release: 2016-05-16 16:47:13
Original
1204 people have browsed it

Someone may ask what format this is?
Actually, there’s more.
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 decimal only. Let's talk about 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 octal. (The 0 here is the number 0, not the letter o)
Some friends may have questioned, isn’t this decimal? How do you say it is octal?
Actually, this is the octal system, just adding a 0 before the decimal system.

JavaScript study notes--numeric format type_javascript skills

Of course not everything plus 0 is octal.
For example, 08, 09 is actually decimal, because there is a carry from octal to 8, so 08, 09 is impossible.

JavaScript study notes--numeric format type_javascript skills

Do you feel that your horizons are much broader? You are no longer limited to the decimal representation form, and you don’t have to be afraid of being scared by the code written by the big cow.

Some friends may ask, do octal and hexadecimal support e - format?

JavaScript study notes--numeric format type_javascript skills

0x12e3 === 4835
0x12e 3 === 305
0x12e-3 === 299
0x12 === 18
Obviously, this is not the result we expected.
In fact, 0x12e3 is because e is also a character in hexadecimal. Hexadecimal characters are 0-9 plus a-f. The case does not matter, so 0x12e3 is a normal hexadecimal number format.
0x12e 3 Why not? In fact, it is just the addition of two numbers. The decimal notation of 0x12e is 302. Add 3 to get 305, so it is an expression, not a simple number.

The format of 011e2 is also incorrect, and may even directly report a syntax error.
So the exponential format can only be used in decimal.

Don’t naively mistake it for IE6 when you encounter 1e6 in the future.
Don’t be depressed anymore about why .5 does not go wrong and why .1e1 is equal to 1.

Okay, today I will share this little knowledge point and think about it slowly by yourself.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template