grzesiek Posted February 24, 2016 Posted February 24, 2016 Shouldn't this return 1? Local $v = (24.60 * 1.3) / 1.23 MsgBox(0,"",IsInt($v)) This returns 1. Local $v = 31.98 / 1.23 MsgBox(0,"",IsInt($v))
Moderators Melba23 Posted February 24, 2016 Moderators Posted February 24, 2016 (edited) grzesiek, Does this give you a hint as to why it does not? Local $v = (24.60 * 1.3) / 1.23 ConsoleWrite($v & @CRLF) ConsoleWrite(VarGetType($v) & @CRLF) ConsoleWrite(IsInt($v) & @CRLF) ConsoleWrite(Hex($v) & @CRLF) ConsoleWrite(@CRLF) Local $w = 31.98 / 1.23 ConsoleWrite($w & @CRLF) ConsoleWrite(VarGetType($w) & @CRLF) ConsoleWrite(IsInt($w) & @CRLF) ConsoleWrite(Hex($w) & @CRLF) ConsoleWrite(@CRLF) ConsoleWrite(($v = $w) & @CRLF) M23 Edited February 24, 2016 by Melba23 Wrong button - too soon 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
czardas Posted February 24, 2016 Posted February 24, 2016 (edited) Floating point maths is not always 100% accurate - it's just fast. There is a margin of error which is normally very small. Using Int() will force an integer, but you can only do that if you know the result is an integer. I have spent time looking into this and written a library of functions to do simple calculations of this type using fractions: https://www.autoitscript.com/forum/topic/165558-fraction/ It's more bother to use fractions, but wildly more accurate than floats are ever likely to be, either now or in the future. Edited February 24, 2016 by czardas operator64 ArrayWorkshop
iamtheky Posted February 24, 2016 Posted February 24, 2016 you can always asc / 2 Local $v = (24.60 * 1.3) / 1.23 Local $frmt = Asc(Hex($v)) / 2 msgbox(0, '' , $frmt & @LF & VarGetType($frmt) & @LF & IsInt($frmt)) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
czardas Posted February 24, 2016 Posted February 24, 2016 21 minutes ago, iamtheky said: you can always asc / 2 No you can't. It doesn't work. operator64 ArrayWorkshop
iamtheky Posted February 24, 2016 Posted February 24, 2016 (edited) 26 - double - 1 what exactly is not working? unless your issue was with *always*, and i would concede that there may be edge cases Edited February 24, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
czardas Posted February 24, 2016 Posted February 24, 2016 (edited) I didn't say VarGetType isn't working. This gives the wrong answer (or rather it gives the same answer, which can't be right): Local $v = (24.67 * 1.3) / 1.23 Local $frmt = Asc(Hex($v)) / 2 msgbox(0, '' , $frmt & @LF & VarGetType($frmt) & @LF & IsInt($frmt)) Edited February 24, 2016 by czardas operator64 ArrayWorkshop
iamtheky Posted February 24, 2016 Posted February 24, 2016 (edited) cmon! every answer is 52 I expected a right proper dismantling Edited February 24, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
czardas Posted February 24, 2016 Posted February 24, 2016 You would have got one, if chrome would have allowed me to post it. operator64 ArrayWorkshop
grzesiek Posted February 25, 2016 Author Posted February 25, 2016 T Quote Thank you for your answers.
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