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 / Dividing a number

Author
Message
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 11th Dec 2003 12:38
lol this is really noobish, but I've never done it before and now that I'm trying to, it's not working as I would have expected. The following code should return 3.5, right?



Why doesn't it? And if there's a logical reason, how do I get it to?


"Computers are useless they can only give you answers."
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 11th Dec 2003 13:07
define the 2 numbers a little more perhaps

Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 11th Dec 2003 14:25 Edited at: 11th Dec 2003 14:31
Ahh, nice work. Cheers.

The real problem though is that my two numbers are in Integer variables, I guess it would work if I defined them as Real variables but that would mess things up in a different section of code. Ideally I'd like a way to convert them to Real Numbers so I can divide them and get a decimal, is there a command like "Int" for this?

I guess if that fails I can always do it the other way and make them real and use "Int" everytime I need them as integers. Thanks.


"Computers are useless they can only give you answers."
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 11th Dec 2003 14:36 Edited at: 11th Dec 2003 14:37
Cheat, as long as you introduce a real number into the formula, then answer will be a real number



Boo!
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 11th Dec 2003 14:41
There is a int command, at least in Classic



Should work

I am mischeivious
RoooooOoooooKoooooKoooooRoooooOoooooKoooooKooooo!
Dave J
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Feb 2003
Location: Secret Military Pub, Down Under
Posted: 11th Dec 2003 14:45
Mattman, I'm talking about a 'Real' command, like the equivalent of Int but to make them Real Numbers.

Thanks Spooky, that seems to work.

Also, one last thing (I'm new to these Real numbers lol), is it just me, or are they terribly inaccurate?



Should return 5.1 logically, but in the code it returns 5.099999990463 - I guess I don't need to be that accurate, but it's still strange.


"Computers are useless they can only give you answers."
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Dec 2003 23:03
What you're talking about earlier is casting. You could define your variables as double or float or whatever. Then when you need to use them as an integer, you could use int(variable#). At least I think that's the command. But in DBP, I'm pretty sure the functions do automatic casting.
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 13th Dec 2003 17:41
ive heard that that innacuracy problem is on any language compiler, its a problem with teh CPU and floating point variables not just darkbasic
Daris Xiao or Benjy Wright
20
Years of Service
User Offline
Joined: 13th Dec 2003
Location: Face first in a bowl of soup.
Posted: 13th Dec 2003 21:28

WOW! Hey, Exeat! Who Drew Your Logo Thingy! That Is Sweet!!!
If You Drew It, Where's Your Website! I Wanna Visit!

Login to post a reply

Server time is: 2024-11-25 20:34:57
Your offset time is: 2024-11-25 20:34:57