grzesiek

IsInt

10 posts in this topic

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))

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 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._______My UDFs:

Spoiler

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

#3 ·  Posted (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 by czardas

Share this post


Link to post
Share on other sites

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))

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
21 minutes ago, iamtheky said:

you can always asc / 2

No you can't. It doesn't work. :huh:

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by czardas

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

cmon!  every answer is 52 :)

I expected a right proper dismantling

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

T

Quote

Thank you for your answers.

 

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