简体   繁体   English

javascript(toFixed)方法有什么问题?

[英]What's wrong with javascript (toFixed) method?

What's wrong with this code? 此代码有什么问题?

var result = 985.toFixed(2);

And the fix is: 而解决方法是:

var result = (985).toFixed(2);

I still want to know the reason. 我仍然想知道原因。 :) :)

In the first example, the Javascript interpreter interprets the dot as a decimal point, because it's coming after a number. 在第一个示例中,JavaScript解释器将点解释为小数点,因为它在数字之后。

Putting brackets around the number gets around this limitation. 将括号放在数字周围可避免出现此限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM