JavaScript Number Literals aka Constants

JavaScript FAQ | JavaScript Numbers FAQ  

Question: What number formats can I use in JavaScript code?

Answer: In JavaScript code, you can write number literals and mathematical constants in several different ways:

  • conventional decimal numbers:
     0 
    1 
    5 
    137 
    1.3 
  • decimal numbers in exponential form:
     6.67e-11 
     -1.127e20 
  • octal numbers, for example:
     -077 
     01234 
    0312 

    Positive octal numbers must begin with
    0
    (zero)
    Negative octal numbers must begin with
    -0
    .
  • hexadecimal numbers, for example:
     0xFF 
    -0xCCFF 
    0xabcdef 

    Positive hexadecimals must begin with
    0x

    Negative hexadecimals must begin with
    -0x
  • predefined mathematical constants (properties of the
    Math
    object)
Regardless of the number format you use, internally JavaScript stores all numbers as double-precision floating-point values (according to the IEEE 754 Standard).

See also:

Copyright © 1996-2018, JavascriptFAQ.net.