2 equal numbers that are not equal?

I have this

print(totalPayment, totalChange, totalPayment > totalChange, totalPayment < totalChange)
It outputs 5.71 5.71 false true. I also used typeof and they’re both “number”.
So, we have two numbers that are the same but are not “==”, since 5.71 is smaller than 5.71?

What is a workaround for this? I need to check if they are exactly the same, not bigger, not smaller.

can u elaborate the question or show the full script cause am not seeing any comaparing functions here.

It’s on the print, if you print (a > b) it will output either true or false.

I did print(totalPayment == totalChange) and I got false, bigger than false as well, but smaller than is true

Your issue is likely floating point imprecision, not much you can do about that. A few alternatives are multiplying by 10 to get a whole number, and comparing those, then dividing by 10 when necessary. Another is to just round to an integer and compare that way and deal with inaccuracies.

1 Like

Really? This is normal as 5.71 is greater than 5.17 unless you’re using some sort of nonstandard numbering system that otherwise says so.

Why do you think comparing number literals as opposed to creating a variable and “referencing” (IIRC numbers are passed by value, not reference) it, will confuse the two?

1 Like

And I just realised I made a mistake :laughing:. I revoke my post.