Standard built-ins
Number.prototype.toFixed()
Produces fixed decimal notation for ordinary finite values with magnitude below 10^21; larger magnitudes use number-to-string. Fraction digits range 0–100, default 0. Out-of-range digit counts can throw RangeError. Result is text; binary representation influences rounding.
Formal Syntax & Structure
javascript syntaxjavascript
number.toFixed(fractionDigits?)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fractionDigits | number | Fractional digit count 0–100. |
Return Value
string
Formatted Number.
Working Example
Example Snippetjavascript
console.log((12.5).toFixed(2));