English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
toFixed()The method uses fixed-point notation to format numbers.
If necessary, numbers will be rounded, and if necessary, the decimal part will be filled with zeros to have the specified length.
number.toFixed(digits)
var num = 12345.6789; num.toFixed(2);Test and see‹/›
All browsers fully support the toFixed() method:
Method | |||||
toFixed() | Is | Is | Is | Is | Is |
Parameter | Description |
---|---|
digits | (Optional) the number of digits that appear after the decimal point; this may be a 0 to2values between 0 and, and the implementation may support larger ranges of values. If this parameter is omitted, it will be considered as 0 |
Return value: | Represent the string of the given number in fixed-point notation |
---|---|
Exception cases: |
|
JavaScript Version: | ECMAScript 3 |
Convert numbers without retaining any decimal places:
var num = 12345.6789; num.toFixed();Test and see‹/›
If necessary, pad the decimal part with zeros:
var num = 12345.6789; num.toFixed(10);Test and see‹/›