toFixed Method

Top  Previous  Next

Converts a number into a string, keeping a specified number of decimals.

Syntax

number1.toFixed(number2)

Arguments

number1A number representing the number to be converted into a string.
number2An integer between 0 and 21 representing the number of digits in the notation after the decimal point; whereas the default is 0.

Return Value

The number as an exponential notation.

Remarks

If the argument is missing, it is set to 6 digits to represent the exponential value of the given number. if the argument is higher than 21 higher, nulls are added to create the actual decimal length. If the argument is 0, it returns a number which represents the nearest integer of the number (see Math.round()).

Examples

var num= 5.85236;

var n=num.toExponential(4);   // Returns 5.8524