I would like to format my numbers to always display 2 decimal places, rounding where applicable.
(我想将数字格式化为始终显示2个小数位,并在适用的情况下四舍五入。)
Examples:
(例子:)
number display
------ -------
1 1.00
1.341 1.34
1.345 1.35
I have been using this:
(我一直在使用这个:)
parseFloat(num).toFixed(2);
But it's displaying 1
as 1
, rather than 1.00
.
(但是它显示1
为1
而不是1.00
。)
ask by Varada translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…