javascript - How to determine whether a value with decimals in js is equal to 0
世界只因有你
世界只因有你 2017-05-16 13:06:55
0
4
512

Is 0.05 equal to 0

Is 0.00 equal to 0

I use parseinit. . . Something went wrong

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

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