zeropointone Posted April 28, 2014 Share Posted April 28, 2014 I need some help with this problem. MsgBox(0, "", 0.29 * 100) If I run this code, it outputs the value 29, as it should. But... MsgBox(0, "", Floor(0.29 * 100)) If I run this code, it outputs the value 28. ?! Can anyone help me out here? Link to comment Share on other sites More sharing options...
czardas Posted April 28, 2014 Share Posted April 28, 2014 (edited) The problem is that 0.29 is a floating point number. The calculated answer is also a float, very close, but not quite 29. Using Floor() is correctly removing everything after the decimal point and returning 28. Check out the function Round(), it should be useful here. Also see Int(). Edited April 28, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
zeropointone Posted April 28, 2014 Author Share Posted April 28, 2014 Thanks czardas, I'll test those functions on my code soon. If the problem is a floating point arithmetic error, then I'd expect 0.29 * 100 to equal 28.9999... But 0.29 * 100 = 29 in both AutoIt and C++, so that's why I was hoping there was another work around! Link to comment Share on other sites More sharing options...
czardas Posted April 28, 2014 Share Posted April 28, 2014 (edited) Floor() is meant to behave that way. Floor(28.9999999999999) returns 28, and Ceiling(1.00000000000001) returns 2. Edited April 28, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Unc3nZureD Posted April 28, 2014 Share Posted April 28, 2014 Try this one: MsgBox(0, "", Floor(0.29 * 100)) MsgBox(0, "", Floor(0.39 * 100)) Then why does the second one works, meanwhile the first isn't? I've got no idea what's going on Link to comment Share on other sites More sharing options...
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