Jump to content

Comparing large numbers returns false


tosfera

Recommended Posts

I've got some proper brainf*cking material right here. I'm comparing someone's money ( both int values ) and the debugs are outputting the same values. By using tonumber the results end up being false. If I change them to a string, it works. The debugs below are the results including their type;

number type;

check: false 
value1: 695.41000000001 [type] number 
value2: 695.41000000001 [type] number 

string type;

check: true 
value1: 695.41000000001 [type] string 
value2: 695.41000000001 [type] string 

The check goes as following;

if ( tonumber ( elementMoney ) == tonumber ( itemMoney ) ) then -- returns false 
if ( tostring ( elementMoney ) == tostring ( itemMoney ) ) then -- returns true 

Why in seven hells is the check going wrong if I'm parsing them to a number but works if I parse them to a string? :lol:

Link to comment
  • Moderators

You sure they are integer values? Because they look more like floats to me.

if elementMoney == itemMoney then 

And what is this result? Maybe the tonumber has something to with it.

if tonumber(tostring(elementMoney)) == tonumber(tostring(itemMoney)) then 

And this?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...