Convert a number into a string, keeping only two decimals:
The result of n will be:
The toFixed() method converts a number into a string, keeping a specified number of decimals.
Note: if the desired number of decimals are higher than the actual number, nulls are added to create the desired decimal length.
![]()
The toFixed() method is supported in all major browsers.
| Parameter | Description |
|---|---|
| x | Optional. The number of digits after the decimal point. Default is 0 (no digits after the decimal point) |
| Type | Description |
|---|---|
| String | The number, with the exact number of decimals |
| JavaScript Version: | 1.5 |
|---|
Convert a number, without keeping any decimals:
The result of n will be:
Convert a number which has fewer decimal places than requested:
The result of n will be:
JavaScript Number Object
Your message has been sent to W3Schools.