Jump to content

8.20 - 8.00 = 0.199999999999999


Recommended Posts

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

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

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
 Share

  • Recently Browsing   0 members

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