Export (0) Print
Expand All

toFixed Method (Number) (JavaScript)

Represents a number in fixed-point notation.

numObj.toFixed([fractionDigits])

numObj

Required A Number object.

fractionDigits

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

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.

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

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 (JavaScript)

Show:
© 2014 Microsoft