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 / DBProfessional division?!

Author
Message
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 12th Feb 2014 12:34 Edited at: 12th Feb 2014 12:39
Hi guys, I am just getting krazy..

I make this calculation:

I obtain -----> 0

If I make same calculation using the windows calculator I obtain 0.75...

So I tried with this calculation:

I obtain -----> 2 !!!!
Using windows calculator I obtain 2.5

So WTF!! I tried to name the variable as float too but nothing change.

In other words, using DBPro, can I obtain a real number as result doing a division????
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 12th Feb 2014 12:42 Edited at: 12th Feb 2014 12:46
If you wish to obtain a float value from a calculation, at least one of the numbers used must be a float.




[edit]In the above examples the values used are literal and so its easy to simply add a ".0" to the end, but if you wish to use integer variables then a solution is to add 0.0 to one of the variables

Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 12th Feb 2014 12:46
........ thank you revenant chaos......

Now I understand a lot of bugs..
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Feb 2014 12:53 Edited at: 12th Feb 2014 12:54
Guess - I think it's because the calculation is data type specific and doesn't take into account what data type it will be stored in. So DBP would do this:

Integer Result = 75/100 = 0 (rounded because .xxx can't be stored in an integer)

Float Result = Integer Result = 0

The way to resolve this is to convert one of the integers to a float. A simple way would be:

Float Result = (1.0 * 75)/100 = 75.0/100 = 0.75

EDIT: revenant chaos beat me

"Get in the Van!" - Van B
Alduce
23
Years of Service
User Offline
Joined: 26th Oct 2002
Location: Rama spaceship
Posted: 12th Feb 2014 12:54
Thank you too Sasuke!
revenant chaos
DBPro Master
19
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Robbinsdale, MN
Posted: 12th Feb 2014 12:59
You're welcome, I'm always glad to help.
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Feb 2014 13:27 Edited at: 12th Feb 2014 13:27
Cheers and I never thought of doing +0.0, that's a good idea revenant

"Get in the Van!" - Van B

Login to post a reply

Server time is: 2026-07-06 10:36:13
Your offset time is: 2026-07-06 10:36:13