Java Reference
In-Depth Information
If a number starts with a zero, it is usually considered to be in octal (base 8) notation:
047; // 4 eights and 7 units
<< 39
Octal numbers are not actually part of the ECMAScript standard, but many JavaScript en-
gines implement this convention.
Exponential Notation
Numbers can also be represented in exponential notation, which is shorthand for "multiply
by 10 to the power of" (you may have heard this referred to as "scientific notation" or
"standard form"). Here are some examples:
1e6; // means 1 multiplied by 10 to the power 6 (a million)
<< 1000000
2E3; // can also be written as 2E3, 2E+3 and 2e+3
<< 2000
Fractional values can be created by using a negative index value:
2.5e-3; // means 2.5 multiplied by 10 to the power -3
<< 0.0025
Number Methods
Numbers also have some built-in methods, although you need to be careful when using the
dot notation with number literals that are integers because the dot can be confused for a
decimal point. There are a few ways to deal with this, which we'll demonstrate with the
toExponential() method; this returns the number as a string in exponential notation.
Use two dots:
5..toExponential(); >> "5e+0"
Search WWH ::

Custom Search