Bookshelf Home | Contents | Index | PDF

### toExponential() Method

This function returns a number converted to exponential notation with a specified number of decimal places in its mantissa.

##### Syntax

numberVar.toExponential(len)

Parameter
Description

len

The number of decimal places in the mantissa of the exponential notation to which the number contained in variable numberVar is to be converted

##### Returns

This function returns the number contained in variable numberVar, expressed in exponential notation to len decimal places. If len is less than the number of significant decimal places of numberVar, then the function applies standard rounding (round up for 5 or greater, else round down). If len is greater than the number of significant decimal places of numberVar, then the function pads the extra places with zeroes. If len is negative, an error is thrown.

##### Usage

This function allows you to express numbers in exponential notation with a desired number of decimal places. Exponential notation is generally used to express very large or very small numbers. Because the mantissa of a number expressed in exponential notation is always exactly one digit, controlling the number of decimal places is also a means of controlling the number of significant digits in the number. The justified accuracy of the number may limit the number of signficant digits.

##### Example

The following uses of toExponential() yield the results shown.

var num = 1234.567
var num3 = num.toExponential(3) //returns 1.235e+3
var num2 = num.toExponential(0) //returns 1e+3
var num9 = num.toExponential(9) //returns 1.234567000e+3

var smallnum = 0.0001234
var smallnum2 = smallnum.toExponential(2) //returns 1.2e-4
var smallnumerr = smallnum.toExponential(-1) //throws error