# math problem

## Recommended Posts

Hi everyone, I can't figure this out. I am simply trying to multiply two numbers and have a msgbox open, but even though the number equals 1.7955 it won't open the msgbox. What am I doing wrong? I am using version 3.3.6.1. Thank you.

```\$runningpercent = 1.89
\$average = 0.95
\$total = \$runningpercent * \$average
If \$total = 1.7955 Then MsgBox(4096, "\$mynumber", 1.7955)```

##### Share on other sites

Why aren't you using V3.3.8.1? Anyway use == to compare if the value is equal.

```Local \$nRunningPercent = 1.89
Local \$nAverage = 0.95
Local \$nTotal = \$nRunningPercent * \$nAverage
If \$nTotal == 1.7955 Then
MsgBox(4096, '', 1.7955)
EndIf```

##### Share on other sites

Hi guinness, my understanding from the help file is that == is only used for string comparisons that need to be case sensitive. Since these are numerical values, why would = not work?

##### Share on other sites

ok, that's a good enough answer for me. can i use == when testing any type of number, whether they are floating or integers?

##### Share on other sites

Hi guinness, the == seems to work, but >= or <= does not. using the example from above, how do you get this to work? i get an error if i try to put >==

```\$runningpercent = 1.89
\$average = 0.95
\$total = \$runningpercent * \$average
If \$total >= 1.7955 Then MsgBox(4096, "\$total", >=1.7955)```

##### Share on other sites

how do you get this to work? i get an error if i try to put >==

```Local \$nRunningPercent = 1.89
Local \$nAverage = 0.95
Local \$nTotal = \$nRunningPercent * \$nAverage
If \$nTotal > 1.7955 Or \$nTotal == 1.7955 Then
MsgBox(4096, '', 1.7955)
EndIf```

##### Share on other sites

ok, that's cool. do you have any more floating point tips that you can share with me?

##### Share on other sites

since these are mathematically generated numbers, i don't know if the values will be floats or integers. will the use of == work with integers as well, both positive and negative?

##### Share on other sites

i will rebuild using this method and compare to previous results. thank you guinness for your help.

##### Share on other sites

This seems to be a decimal problem!

As a workaround you can use the Round() function.

```\$runningpercent = 1.89
\$average = 0.95
\$total = \$runningpercent * \$average
ConsoleWrite(\$total - 1.7955 & @CRLF)

If Round(\$total, 4) = 1.7955  Then MsgBox(4096, "\$mynumber", 1.7955)```

Br,

UEZ

Edited by UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

The double type contains 64 bits: 1 for sign, 11 for the exponent, and 52 for the mantissa. Its range is +/–1.7E308 with at least 15 digits of precision.

```\$runningpercent = 1.89
\$average = 0.95
\$total = \$runningpercent * \$average
If Round(\$total, 15) = 1.7955 Then MsgBox(4096, "\$mynumber", 1.7955)```

##### Share on other sites

That's always been there. Thanks to Intel. Anyway, BEZ, search the forums and the dev-side. There's quite a bit of discussion on rounding and the errors it produces.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

##### Share on other sites

The issue here is that only a very incredibly small number of decimal values (e.g. NOT 1.89 or 0.95) can be represented exactly in binary floating-point.

We're still having this problem, more than 20 years after the first IEEE standard, that no exact definition of what should be the addittion of two FP values is available.

From this, it's no wonder that multiplying imprecise values give imprecise results.

BTW, this problem isn't specific to AutoIt since every programming language using hardware binary FP has the same issues.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...