Description
The toFixed() method is used to format a number to use a specified number of trailing decimals.
The number is rounded up, and nulls are added after the decimal point (if needed), to create the desired decimal length.
This method has the form:
number.toFixed(x)
Parameter | Description |
---|---|
x | (optional) The number of digits after the decimal point. Default is 0 (no digits after the decimal point) |
Examples
The following example shows the basic use of this method.
<script>
var num = new Number(123.45);
document.write(num.toFixed());
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|