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:

  • Can I display mathematical symbols as part of JavaScript output?
  • Can I display Greek letters on my page as part of JavaScript output?
  • Mathematical functions in JavaScript
  • Mathematical constants in JavaScript
  • Random numbers in JavaScript
  • Rounding in JavaScript
  • Accuracy of JavaScript arithmetic
  • Copyright © 1999-2012, JavaScripter.net.