Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Div, Mod and variables

Status
Not open for further replies.

gwar2k1

Programmer
Apr 17, 2003
387
GB
Why dont DIV and MOD let you use variables? Im trying to do <real variable> DIV <constant number> but it says operand error.

Its just silly if you ask me! hehe.

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
DIV and MOD are for integer division:

A div B = C
A mod B = D
A = B * C + D


Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
MOD wouldn't make any sense with a real variable, because the point of MOD is to return the remainder, while a real variable is designed to store the fraction....

If you want to get the remainder from a division of a real (or any other floating point) number is to move it into an integer first. Use the round/trunc etc. to get the right integer. If you want the effect of div, just divide with /, and then truncate.

Best wishes!
 
Stupidity on my part i guess! lol i was using real variables, didnt cross my mind it should be integer type =P Thanks, hopefully Ill keep these stupid questions to a minimum lol

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Don't worry. I like stupid questions because they're easier to answer.... (and how many times have I got in a panic because 3 div 4 * 100 was't 75???)
 
lol k. =D

~*Gwar3k1*~
&quot;To the pressure, everything's just like: an illusion. I'll be losing you before long...&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top