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 / Doing something every 100th cycle...problems with real numbers

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Apr 2003 15:47 Edited at: 4th Apr 2003 15:48
Hi,

I'm doing Ok so far with DB - very easy to get to grips with. However, I am having a problem with real numbers.

I want to compare the a real number with an INTeger and do something if they match. That is, do something every 100th cycle (see the code). However, my real number has no decimal places...

For y = 1 to 3000
x# = y / 100
if x# = INT(x#) then ...
Next y

x# never has any decimal points, and therefore the IF clause is always true. Is it because y is an integer? I would have thought the decimals are controlled by the result field, not the field you are equating.

Any help is much appreciated!

Thanks in advance,
StevieVee

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Apr 2003 15:48 Edited at: 4th Apr 2003 15:49
Oops! <deleted by myself>

Shadow
22
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 4th Apr 2003 16:13
Try this:

For y = 1 to 3000
x# = y / 100.0
if x# = INT(x#) then ...
Next y
GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 4th Apr 2003 17:42
hmmm... try

For y = 1 to 3000
if y/100 = INT(y/100) then ...
Next y

i don't know if it works, but i hope it helps some...

Anyone Can Destroy...But Few Can Create...
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Apr 2003 19:10
Thanks guys, I'll try your suggestions.

I think I already tried the y/100 = INT(y/100) without success, and continued by breaking the problem down into smaller steps to see if it helped any.

I've seen the concept of ending a number in .0 elsewhere to force it to a real number. Hopefully I can combine the 2 ideas into one statement.

Thanks in advance.
All the Best,
StevieVee
Scorpyo
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: italy
Posted: 4th Apr 2003 22:30
Try this (copy and paste):

cls
For y = 1 to 3000
y#=y
x#=y#/100
cls
set cursor 0,0
if INT(x#)*100=y then print "OK"
print "y#=",y#
print "x#=",x#
print "int(x#)*100=",int(x#)*100
wait key
Next y

Just remove the print, wait key and cls stuff to use it in your code

cheers
Scorpyo
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Apr 2003 23:24
Absolutely no need to use floating point for this.



However, in your original code change this 'x# = y / 100' to this 'x# = y / 100.0' and it should work.

Login to post a reply

Server time is: 2024-11-24 08:49:26
Your offset time is: 2024-11-24 08:49:26