Easy Tutorial
❮ Event Img Onerror Dom Obj Keygen ❯

JavaScript toFixed() Method

JavaScript Number Object

Example

Convert a number into a string, rounding to a specified number of decimals:

n Output result:


Definition and Usage

The toFixed() method converts a number into a string, rounding to a specified number of decimals.


Browser Support

All major browsers support the toFixed() method.


Syntax

Parameter Values

Parameter Description
x Required. Specifies the number of digits after the decimal point. It is a value between 0 and 20, inclusive, but some implementations may support a wider range of values. If omitted, it defaults to 0.

Return Value

Type Description
String A string representing the given number rounded to x decimal places

Technical Details

| JavaScript Version: | 1.5 | | --- | --- |


More Examples

Example

Convert a number with no decimal places:

n Output result:

Example

Convert a number with fewer decimal places than specified:

var num = 5.56789;
var n = num.toFixed(10);

n Output result:

var num = 5.56789;
document.write(num.toFixed(10));

JavaScript Number Object

❮ Event Img Onerror Dom Obj Keygen ❯