VitAl2013 Posted May 17, 2009 Share Posted May 17, 2009 #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)GUISetState(@SW_SHOW)#EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 $target = GUICtrlRead ($input) lenght_analiz ($target) Case $GUI_EVENT_CLOSE Exit EndSwitchWEnd 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) ExitEndFuncAfter minus operation I have 0.081999999999 and not 0.082. Why and what to do? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 17, 2009 Moderators Share Posted May 17, 2009 (edited) VitAl2013, It is a floating point arithmetic problem. Look at this thread. M23 Edit: Welcome to the AutoIt forums, by the way! Edited May 17, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
martin Posted May 17, 2009 Share Posted May 17, 2009 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now