Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Determing if a number is a whole number

Author
Message
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 16th Mar 2004 03:16
I am trying to determine whether a number is a whole number or not.

If I try to compare the number to it's integer equivalent (i.e. var# = int(var#) ) I always get true - even if var# contains 1.0234 or whatever.

It's driving me around the twist!

Any help would be appreciated.
Trowbee
21
Years of Service
User Offline
Joined: 12th Apr 2003
Location: United Kingdom
Posted: 16th Mar 2004 03:23
strange, it works ok with mine (both DBC and DBP)

Xander
21
Years of Service
User Offline
Joined: 3rd Mar 2003
Location: In college...yeah!
Posted: 16th Mar 2004 04:27
Yeah, that should work...That is how I would do it...

Are you sure that you are using a float and not an interger (I don't think you are stupid, I do stupid stuff too, you can't bee too careful)

ex:
var=int(var)

vs

var#=int(var#)

Xander Moser of Bolt Software
Firewall: Your Computer's First Defense - Real Time Strategy game
[href][/href]
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 16th Mar 2004 10:51
As far as I can tell I am comparing a float to an integer - when I print the variable I consider a float it does include the decimal point and fraction components - I'll go back through and have another look through as this has to be something immensely elementary that I am doing wrong.

Thanks for the assistance - I am very new to DBPro (not programming itself).
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 16th Mar 2004 23:57
OK Something really odd going on here.

I tried just Trowbee's snippet in a brand new blank program and when I ran it, I got the same value for Int(v#) and (Int(v#)=v#) - both times it returned 1.

My own snippet in a blank brand new program also gets 1 as the result of both comparisons.

This really is driving me nuts.
DarkSin
21
Years of Service
User Offline
Joined: 23rd Jul 2003
Location: Under your bed
Posted: 17th Mar 2004 01:44
what version are you using? (dont know if that may or may not make a diffrence or not in this case)


Trowbee
21
Years of Service
User Offline
Joined: 12th Apr 2003
Location: United Kingdom
Posted: 17th Mar 2004 04:54
Your snippet does the same as mine, on my computer anyway.

DBP (Patch 5.2, Version 1.052)
DBC (Patch 1.14)
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 17th Mar 2004 12:10
I got DBP 5.2

When I run your snippet I get 0 & 1
Scouseknight
20
Years of Service
User Offline
Joined: 15th Mar 2004
Location: Bootle, Merseyside, UK
Posted: 17th Mar 2004 21:26
I was running the original version of Darkbasic Professional as installed from the CD - I have just updated to 1.052 and the calculations are now working as expected.

Thanks to everyone who helped me on this - at least I know it wasn't me going around the twist!

Login to post a reply

Server time is: 2024-11-26 09:30:44
Your offset time is: 2024-11-26 09:30:44