Jump to content
Sign in to follow this  
level20peon

8.20 - 8.00 = 0.199999999999999

Recommended Posts

level20peon

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 ?

Share this post


Link to post
Share on other sites
foster74

Very strange, even Execute() doesn't help. Maybe use Round() for the time being?

Share this post


Link to post
Share on other sites
Malkey

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.

Share this post


Link to post
Share on other sites
level20peon

Thanks, didn't come up when I searched the forum for math functions.

Share this post


Link to post
Share on other sites
Richard Robertson

The problem isn't directly related to AutoIt. All programs that use floating point arithmetic suffer from this.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×