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.
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.
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?