How to write Scientific notation literal in Javascript

Description

Floating-point values can be represented using e-notation.

E-notation indicates a number that should be multiplied by 10 raised to a given power.

The format of e-notation in Javascript is to have a number, integer or floating-point, followed by e or E, than by the power of 10 to multiply by.

Example

Consider the following:


var floatNum = 3.125e7;    //equal to 31250000
console.log(floatNum);

In this example, floatNum is equal to 31,250,000. The notation essentially says, "Take 3.125 and multiply it by 10 7."

The code above generates the following result.

Note

E-notation can also be used to represent very small numbers, such as 0.00000000000000003, which can be written more succinctly as 3e-17.

By default, Javascript converts any floating-point value with at least six zeros after the decimal point into e-notation.





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions