Tumble Posted February 25, 2018 Share Posted February 25, 2018 #include <MsgBoxConstants.au3> $var1 = 250000 $var2 = $var1 / 2500 $var3 = 250 MsgBox( $MB_SYSTEMMODAL, "", "$var1: " + $var1 ) ;Shows 250000 MsgBox( $MB_SYSTEMMODAL, "", "$var2: " + $var2 ) ;Shows 100 MsgBox( $MB_SYSTEMMODAL, "", "$var3: " + $var3 ) ;Shows 250 MsgBox( $MB_SYSTEMMODAL, "", "$var3/$var2: " + $var2/$var2 ) ;Shows 1 Here is my code snippet that is acting up. For some reason the variables go in correctly, but they don't come out correctly. Basically my program gets a value from a website, then tries to divide it by another value it gets from that website, and then finally divide it by a number from a database. All of my test values come from the website and my database just fine, it's just this little part of the code. From some reason my code is showing my $var3/$var2 = 1 where it should give me 2.5. Can anyone explain to me why this is happening? It happens both in my actual code and in this little test snippet. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 25, 2018 Moderators Share Posted February 25, 2018 (edited) Tumble, Welcome to the AutoIt forums. It looks like you have fallen foul of the "floating point maths" problem - it affects all computers and is not an AutoIt problem per se. Search the forum and you will find many instances of people running into the same problem - and how to solve it. M23 Edited February 26, 2018 by Melba23 28k 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...
Tumble Posted February 25, 2018 Author Share Posted February 25, 2018 MsgBox( $MB_SYSTEMMODAL, "", "$var3/$var2: " + $var3/$var2 ) ;Shows 253 I typed this line incorrectly in my test code. However, I ended up restarting Scite and it started working... Not sure why it was giving me 253 for 250/100. Link to comment Share on other sites More sharing options...
Tumble Posted February 25, 2018 Author Share Posted February 25, 2018 I can't find anything on the forums through the search bar. However it is strange to me that it works in my test code but when the same exact values go into my real code is when I experience issues. When I check the values they all show up how they should, but when I divide $var3/$var2 in my actual code I get something ridiculous. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 25, 2018 Moderators Share Posted February 25, 2018 Tumble, M23 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...
Malkey Posted February 26, 2018 Share Posted February 26, 2018 16 hours ago, Tumble said: #include <MsgBoxConstants.au3> $var1 = 250000 $var2 = $var1 / 2500 $var3 = 250 MsgBox( $MB_SYSTEMMODAL, "", "$var1: " + $var1 ) ;Shows 250000 MsgBox( $MB_SYSTEMMODAL, "", "$var2: " + $var2 ) ;Shows 100 MsgBox( $MB_SYSTEMMODAL, "", "$var3: " + $var3 ) ;Shows 250 MsgBox( $MB_SYSTEMMODAL, "", "$var3/$var2: " + $var2/$var2 ) ;Shows 1 .... From some reason my code is showing my $var3/$var2 = 1 where it should give me 2.5. Can anyone explain to me why this is happening? It happens both in my actual code and in this little test snippet. I can explain why your code is showing $var3/$var2 = 1. It's because your code reads $var2/$var2, which does equal 1. And the arithmetic value of the string, "$var3/$var2: " equals 0. What you should have is: #include <MsgBoxConstants.au3> Local $var3 = 250 Local $var2 = 100 MsgBox($MB_SYSTEMMODAL, "", "$var3/$var2: " & $var3 / $var2) ;Shows $var3/$var2: 2.5 Link to comment Share on other sites More sharing options...
mikell Posted February 26, 2018 Share Posted February 26, 2018 Getting issues with such a creepy mix of strings/numbers/operators is not so surprising anyway 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