Jump to content
Sign in to follow this  

problem of accuracy

Recommended Posts


#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=

$Form2 = GUICreate("primer", 149, 132, 303, 219)

$Button1 = GUICtrlCreateButton("Calc", 24, 24, 97, 57, 0)

$input = GUICtrlCreateInput("2.082", 24, 96, 97, 21)


#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $Button1

$target = GUICtrlRead ($input)

lenght_analiz ($target)





Func lenght_analiz ($len_a)

$ostatok_1 = Round ($len_a)

MsgBox(4096, "step 2", $ostatok_1)

$ostatok_2 = $len_a - $ostatok_1

MsgBox(4096, "step 3", "Strange here: " & $ostatok_2)

$ostatok_3 = StringTrimLeft ($ostatok_2, 2)

MsgBox(4096, "step 4", $ostatok_3)

$result = StringLen($ostatok_3)

MsgBox(4096, "Test", "Answer: " & $result)



After minus operation I have 0.081999999999 and not 0.082. Why and what to do?

Share this post

Link to post
Share on other sites


It is a floating point arithmetic problem. Look at this thread.


Edit: Welcome to the AutoIt forums, by the way!

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

After minus operation I have 0.081999999999 and not 0.082. Why and what to do?

It's been discussed many times, but computers store numbers in a way that means that exact representation is not always possible or not achieved and results will be to the accuracy of the number of bits used for the calculation. If you want to show the result to the nearest 0.0001 then you can do this

MsgBox(4096, "step 3", "Strange here: " & stringformat("%.4f",$ostatok_2))

or you could have done this at an earlier stage

$ostatok_2 = Round($len_a - $ostatok_1,4)

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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