toExponential()  Number  instance method getterS2C Home  « Globals « Number « toExponential()

Description

Returns a string representation of the number in exponential notation.

Syntax

Signature Description
aNumber.toExponential([numOfFractionalDigits])Returns a string representation of the number in exponential notation.

Parameters

Parameter Description
numOfFractionalDigitsAn optional integer specifying the number of fractional digits to display.
  • When omitted the number of fractional digits required to display the number uniquely are used.
  • When used and there are more digits to display than specified, the fractional return of the answer will be rounded appropriately.

Examples

The code below displays some numerical values exponentiated.


// Create an array for strings and populate.
var aNumber = 16.456456456;
var stringValue = new Array(4);
stringValue[0] = aNumber.toExponential(); 
stringValue[1] = aNumber.toExponential(2); // 2 decimal Places
stringValue[2] = aNumber.toExponential(4); // 4 decimal Places
stringValue[3] = aNumber.toExponential(6); // 6 decimal Places
alert(stringValue);

Press the button below to action the above code:


Related Tutorials

JavaScript Advanced Tutorials - Lesson 3 - Number

go to home page Homepage go to top of page Top