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 / Float Issues When Dividing

Author
Message
Somarl
13
Years of Service
User Offline
Joined: 11th Feb 2011
Location: UK
Posted: 18th Jul 2012 17:11
Cant seem to remember how to get round this issue.

Number As float
Number = 100 / 120

Print Number
Wait Key

Returns 0 when what i am after is something like 0.83333333333333 and so on. I know i am missing something, can anyone clarify?
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 18th Jul 2012 21:08
Try this


The reason is that the compiler needs to know to return a float value as you are dividing two Integers, the answer will be an integer. One number must always be a float.

Kezzla
16
Years of Service
User Offline
Joined: 21st Aug 2008
Location: Where beer does flow and men chunder
Posted: 20th Jul 2012 12:07
holy crap, I never knew you could declare a float without a # tag on the end. learn something new every day.

cheers mate.

Sometimes I like to use words out of contents
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 20th Jul 2012 21:53
@Kezzla:
Yeah, it's amazing when you think you have a language waxed and then you get these little oddities that jump up and make your life so much easier. Here's a useful thing I picked up on an unrelated thread recently - credits to Chris Tate:
You can return an evaluation to a variable, C-style!


Until then, I thought you could only do that in c++.

Here's the thread:
http://forum.thegamecreators.com/?m=forum_view&t=198228&b=1

Login to post a reply

Server time is: 2024-11-24 21:07:14
Your offset time is: 2024-11-24 21:07:14