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.

DarkBASIC Professional Discussion / Simple calculation produces zero

Author
Message
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Oct 2012 15:55
I narrowed it down to this:

do
`show action text
text 600,150,str$(((220-120)/(170+128-902)))
loop

I keep getting zero??? The numbers used to be coming from variables but the code would not work as intended, so I kept simplifying and ended up with this, and a zero :-(

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
MummyKillerSLO
17
Years of Service
User Offline
Joined: 5th Jul 2009
Location: Object Position Y(ObjChair)
Posted: 29th Oct 2012 16:07
You're keep getting zero because the numbers you provided are integers. If you divide 100 with -604 the result is -0.1655 but the integer rounds this number to closest whole number (without decimal) - in this case it will be zero.

To fix your problem, make sure to add # at your variables. If you are using numbers, add .0 at the end (example: 100.0) / (-604.0))

Happy to having and using DarkBASIC Professional...
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Oct 2012 18:07 Edited at: 29th Oct 2012 18:10
Like this?

do
`show action text
Var1# = (((220-120)/(170+128-902)))
print var1#
loop

It still gives me a zero :-( I know the difference between integers and real numbers

EDIT: I follow now, I have to add the .0 to all my numbers

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Oct 2012 18:13 Edited at: 29th Oct 2012 18:38
It just gives me a bit of a hassle as the numbers are pixels on the screen. Or rather, it would seem like a hassle, I just add -0.0 or +0.0 to the calculation then it works I keep forgetting this bug

EDIT: And thanks for the help

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 29th Oct 2012 20:20 Edited at: 29th Oct 2012 20:22
to get better result, you can use Goga's String Plugin to calculate equalation in string format:




or..

Quote: "Like this?

do
`show action text
Var1# = (((220-120)/(170+128-902)))
print var1#
loop

It still gives me a zero :-( I know the difference between integers and real numbers

EDIT: I follow now, I have to add the .0 to all my numbers"


change
Var1# = (((220-120)/(170+128-902)))
to
Var1# = (((220.0-120)/(170+128-902)))

Advanced Updater for your games!
Cybermind
Valued Member
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 29th Oct 2012 23:30
@Sergey K: I try to avoid any plug ins the reduce the number of things that could go wrong The string format was just to debug and see what happened. I just add +0.0 in the math so I can just fuel the other variables with integers (They are pixels coordinates on the screen)

The byte chrunchers are coming...
DIVIDING BY ZERO/BECAUSE WE SUCK...

Login to post a reply

Server time is: 2026-07-09 01:51:46
Your offset time is: 2026-07-09 01:51:46