toFixed Method (Number) (JavaScript)

Represents a number in fixed-point notation.

Syntax


numObj.toFixed([fractionDigits])  

Parameters

numObj
Required A Number object.

fractionDigits
Optional. The number of digits after the decimal point. Must be in the range 0 - 20, inclusive.

Return Value

Returns a string representation of a number in fixed-point notation, containing fractionDigits digits after the decimal point.

If fractionDigits is not supplied or undefined, the default value is zero.

Example

The following code shows how to use toFixed.

var num = new Number(123);  
var fix = num.toFixed();  
document.write(fix);  
document.write("<br/>");  

num = new Number(123.456);  
fix = num.toFixed(5);  
document.write(fix);  

// Output:  
// 123  
123.45600  

Requirements

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: Number Object

See Also

toExponential Method (Number)
toPrecision Method (Number)