search

Home  >  Q&A  >  body text

javascript - How to determine whether a value with decimals in js is equal to 0

Is 0.05 equal to 0

Is 0.00 equal to 0

I use parseinit. . . Something went wrong

世界只因有你世界只因有你2807 days ago514

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:08:55

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:08:55

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

    0.000 === 0 // true
    
    0.08 === 0 // false

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:08:55

    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

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 13:08:55

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

    reply
    0
  • Cancelreply