javascript - js带小数的值怎么判断是不是等于0
世界只因有你
世界只因有你 2017-05-16 13:06:55
0
4
469

0.05是不是等于0

0.00是不是等于0

我是用parseinit。。。结果出问题了

世界只因有你
世界只因有你

reply all(4)
洪涛

JavaScript does not strictly distinguish between decimals and integers, so you can directly determine whether they are equal, but it is best to use ===而不是==. Three equal signs are strictly equal. You can search on Baidu for specific differences

......
0.000 is of course equal to 0

洪涛

Just use it===and it’ll be fine

0.000 === 0 // true

0.08 === 0 // false
洪涛

You have to pay attention to the error in decimals. It is best to provide an accuracy judgment, such as Math.abs(a) < 0.0000001

Math.abs(0.1 + 0.2 - 0.3) < 0.0000001 // true
0.1 + 0.2 - 0.3 === 0 // false
刘奇

parseint is converted to plastic. Think about it, what is 0.05 converted to plastic?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!