tosfera Posted February 18, 2016 Share Posted February 18, 2016 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? Link to comment
Captain Cody Posted February 18, 2016 Share Posted February 18, 2016 There's an issue in general with lua that expands the number, messing with the final results. Link to comment
tosfera Posted February 19, 2016 Author Share Posted February 19, 2016 There's an issue in general with lua that expands the number, messing with the final results. So comparing numbers is just a no go in lua? Strings all the way? Link to comment
Moderators IIYAMA Posted February 19, 2016 Moderators Share Posted February 19, 2016 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
tosfera Posted February 19, 2016 Author Share Posted February 19, 2016 if elementMoney == itemMoney then this returns false, which is also weird. They are both integers. I do have to test this one when I get home, will get back to you once I have it. if tonumber(tostring(elementMoney)) == tonumber(tostring(itemMoney)) then Link to comment
Captain Cody Posted February 19, 2016 Share Posted February 19, 2016 Converting it to string, then back to to number may work as IIYAMA stated, as the tostring will cut out any of the random numbers that lua is throwing in on it. Link to comment
Moderators IIYAMA Posted February 21, 2016 Moderators Share Posted February 21, 2016 Problem solved? Link to comment
tosfera Posted February 21, 2016 Author Share Posted February 21, 2016 Problem solved? compared them as strings, that did solve it. No need to create it as numbers since there is no way the money could be transformed with chars in it, too much protection for that on different locations. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now