First of all, we need to know that according to the definition of floating point in JS, the non-integer number type can not be compared with the ==, which also appears 0.1+0.2 is not equal to 0.3, they are actually slightly different values.
Therefore, we had better not use 0.1+0.2==0.3 this kind of judgment method to deal with floating point number judgment, the correct comparison method, should be to use the minimum precision value provided by JS to do the comparison.
Console. log(math.abs (0.1 + 0.2-0.3) <= number.epsilon);Copy the code
This makes it possible to successfully compare sizes between floating point numbers.
A little knowledge every day, progress every day