我们怎样才能在JavaScript中小数点后得到2位数?

时间:2014-04-08 18:44:53

标签: javascript math decimal rounding

例如,

0.14而不是0.1445436

9.94而不是9.94476

9.99而不是9.99996544

8.90而不是8.9

1 个答案:

答案 0 :(得分:0)

 n = 0.14
nDec = n.toFixed(2) 

您需要在数字处抛出toFixed()方法。 parens中的数字是十进制数字的位数。