The toFixed() method formats a number to fixed-point notation (decimal).
SyntaxtoFixed([ fractionDigits ])
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 0.
ExamplesUsing toFixed
to format the decimal presentation of a number.
var pie = 3.14159;
pie.toFixed(0);
pie.toFixed(4);
pie.toFixed(10);
(1.23e+20).toFixed(2);
(1.23e-10).toFixed(2);
-3.1415.toFixed(2);
(-3.1415).toFixed(2);
Remarks Throws
RangeError
when a fractionDigits outside the bounds of 0 - 20 (inclusive) was given.
toFixed(3.9)
will be treated as toFixed(3)
.1e+21
, toFixed()
calls toString()
internally and returns a string in exponential notation.15.7.4.5 Number.prototype.toFixed(fractionDigits)
ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011
AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4