开发者

What's wrong with javascript (toFixed) method?

开发者 https://www.devze.com 2023-01-11 03:52 出处:网络
开发者_Go百科What\'s wrong with this code? var result = 985.toFixed(2); And the fix is: var result = (985).toFixed(2);
开发者_Go百科

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.

Putting brackets around the number gets around this limitation.

0

精彩评论

暂无评论...
验证码 换一张
取 消