# 1.003 * 1000 = 1002.99999989

## Recommended Posts

First i don't know if this is something that you already know. But eater i have some error in coding or AutoIT wasn't designed to do this way.

Its a simple function that calculates four digits in decimal number, eg. 1.256 returns 1256, at least what it suppose to do.

But when i run the code below instead of numbers 1003 i get 1002. It turned out that when 1.003 gets multiplied with 1000 it becomes 1002.99999999989 instead of 1003.

So is this normal because of float number representation in PC or something else I'm not aware of?

```Func Temperature(\$T)
Local \$C0, \$C1, \$C2, \$C3
\$T = \$T *1000
\$C0 = Int(\$T / 1000)
\$C1 = Int((\$T - (\$C0 * 1000)) / 100)
\$C2 = Int((\$T - (\$C0 * 1000) - (\$C1 *100))/10)
\$C3 = Int(\$T - (\$C0 * 1000) - (\$C1 *100) - (\$C2 *10))
ToolTip(\$C0 & \$C1 & \$C2 & \$C3,500,0)
Sleep(3000)
EndFunc

Temperature(1.003)```

##### Share on other sites

That's a problem with the internal representation of decimal numbers as binary. There has been a lengthy discussion about this lately. I will post the link as soon as I find it.

Edit: Here is the

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

##### Share on other sites

from help file

Example

Local \$var = Int(10.793) ;\$var is the integer 10

so why are you using Int? shudnt you use

\$C3 = Round(\$somedata, 0) ?!

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)

There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

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