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
Lucas Tiridath
AGK Developer
15
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 27th Oct 2008 11:30
I thought that floats were real numbers and that real number could take decimal points. This seems to be the case. However it does not seem to work in this bit of code:



The first error seems to just be a rounding error and I can probably live with that. However it does serve to prove that the float can store the answer to the 800 / 1000. The second print of fFloat comes out as zero though... Why is this?

All help is much apreciated.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 27th Oct 2008 14:50
You need to use

800 / 1000.0

or something similar. It calculates the answer, then puts it in the variable. Because the 2 parts of the calculation are integer, it assumes you want an integer result.

kaedroho
17
Years of Service
User Offline
Joined: 21st Aug 2007
Location: Oxford,UK
Posted: 28th Oct 2008 00:33
i have a similar problem, but this isnt with the numbers its with variables.

variable1/variable2
will always return 0 if they both are integers ive tried converting one of them into a float like this variable2#=variable2 but it still isnt working.

Games, Code, 3D Models and more! click here
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th Oct 2008 01:41
DBPro converts datatypes on demand. If you do an integer operation (you have divide) the result will be an integer. The final integer will be converted to a float value when you assign it to a float variable. As you've discovered, this isn't what you usually want.

Integer operator Integer => Integer
Integer operator Float => Float
Float operator Float => Float

... Where operator can be *, /, +, -, ^, =

You have Integer divided by Integer, giving an Integer result. Convert one of those to a float value before doing the division and you'll get a float division and a float result:

Result# = (variable1 + 0.0) / variable2

Login to post a reply

Server time is: 2024-09-27 20:20:51
Your offset time is: 2024-09-27 20:20:51