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 AppGameKit Corner / I don't understand AGK2's math :(

Author
Message
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 24th Nov 2017 23:16
Why does this piece of code give 6.0000 and 5.061728 instead of 6.428571 and 5.061728? Somevar seems to be of integer type and after changing line 3 to somevar=180/280 the output is 0. What am I missing?


Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 25th Nov 2017 03:09
You have also to use floats in the calculation.

try this:

[/url]
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 25th Nov 2017 18:44
Ugh... strange, but thanks... that explains a lot :/
Jack
20
Years of Service
User Offline
Joined: 4th Oct 2004
Location: [Germany]
Posted: 26th Nov 2017 02:35
If you need to stay with the integer, you can do it like this:




[/url]
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Nov 2017 16:19
Quote: "Ugh... strange, but thanks... that explains a lot :/"

Not strange. If only integers are used in a calculation, AppGameKit will only return an integer. It will not cast it to a float on it's own. Thus you need at least 1 float in the equation to return a float as Jack said.

In some languages you could do this:
somevar = (float)180 / 28

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Kot
7
Years of Service
User Offline
Joined: 2nd Mar 2017
Location:
Posted: 27th Nov 2017 20:13
Yeah, but it involves also things like trying to round numbers with given precision (just like str(number,precision)) and many others :/

x#=123.45678
print (round(x#*100)/100)

returns 123 :/

print (Random(0,100)/100)

returns 0 and sometimes 1, while I wanted to get 2-digit random number from 0 to 1 etc.
Thanks for your answers anyway, as I said, they explain a lot.

Login to post a reply

Server time is: 2024-11-24 13:04:27
Your offset time is: 2024-11-24 13:04:27