level20peon Posted May 15, 2009 Share Posted May 15, 2009 I am trying to do a simple substraction in AutoIT. Turned out to be rocket-science. Send("^c") $test = clipget() $varIN = StringReplace($test,",",".") $varOUT = number($varIN) $result = ($varOUT - "8.00") MsgBox(0,"result",$result) I am copying a string to the clipboard "8,00", replace the "," by "." and convert it into a number afterwards. In fact $varOUT returns "8.20", but $varOUT - 8.00 returns 0.199999999999999. What am I missing ? Link to comment Share on other sites More sharing options...
foster74 Posted May 15, 2009 Share Posted May 15, 2009 Very strange, even Execute() doesn't help. Maybe use Round() for the time being? Link to comment Share on other sites More sharing options...
Malkey Posted May 15, 2009 Share Posted May 15, 2009 I am trying to do a simple substraction in AutoIT. Turned out to be rocket-science. Send("^c") $test = clipget() $varIN = StringReplace($test,",",".") $varOUT = number($varIN) $result = ($varOUT - "8.00") MsgBox(0,"result",$result) I am copying a string to the clipboard "8,00", replace the "," by "." and convert it into a number afterwards. In fact $varOUT returns "8.20", but $varOUT - 8.00 returns 0.199999999999999. What am I missing ?You have discovered the floating point problem. See http://www.autoitscript.com/forum/index.ph...st&p=673030 and http://www.autoitscript.com/forum/index.ph...st&p=611629 $result = round($varOUT - "8.00",14) works. Link to comment Share on other sites More sharing options...
level20peon Posted May 15, 2009 Author Share Posted May 15, 2009 Thanks, didn't come up when I searched the forum for math functions. Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 15, 2009 Share Posted May 15, 2009 The problem isn't directly related to AutoIt. All programs that use floating point arithmetic suffer from this. 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