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.

Author
Message
Paradox452
14
Years of Service
User Offline
Joined: 29th Jul 2011
Location:
Posted: 29th Jul 2011 18:40
Whenever I do division in DBP the result is always a whole number. If I wanted the result to end up in a decimal form such as 0.003, how would I go about doing this?

This is my first post on the forums
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Jul 2011 18:52 Edited at: 29th Jul 2011 18:53
Welcome to the forums

If you divide 2 integer numbers, it will give you an integer result:

3 / 2 = 1

If you want a float, then do this:

3 / 2.0 = 1.5

Max P
16
Years of Service
User Offline
Joined: 23rd Jan 2010
Location:
Posted: 29th Jul 2011 18:58
And when storing them in a var make sure you put a # behind the var so darkbasic knows it is a float:
Paradox452
14
Years of Service
User Offline
Joined: 29th Jul 2011
Location:
Posted: 29th Jul 2011 19:05
Ah, thanks so much! No more snappy camera velocity
Hodgey
16
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 30th Jul 2011 00:32 Edited at: 30th Jul 2011 00:34
Remember, as BatVink mentioned, when using operators with floats don't forget to add in atleast one ".0" if you are operating with integers. For example

will print "1" even though it is a float.


will print "1.5" because there is a ".0" at the end of "2"

Login to post a reply

Server time is: 2026-07-11 10:26:11
Your offset time is: 2026-07-11 10:26:11