|
struesdell Beginner
Joined: 30 Nov 2006 Posts: 11 Location: Seattle, WA, USA
|
Posted: Fri Dec 01, 2006 11:54 pm
[1.17] %float question |
So, I'm trying to evalutate the percent value my current health is of my max health. Both my health and max health are provided by the game as integers, and without decimal values.
@health is 2723
@maxhealth is 2966
when I do %float(@health/@maxhealth), it returns 0, where it seems like it should return 0.918071476736345
If from the command line I do #show %float(2723/2966) it returns 0.
If I do #show %float(2723.0/2966.0) it returns 0.918071476736345.
How do I convince %float to behave correctly on inputs that aren't already float values? Alternatively, how do I convince my integer variables to prentend they're float variables for the duration of one evaluation?
EDIT:
So, I went to each of the involved variables and manually set them to the Float type, and this seems to have fixed it. |
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Sat Dec 02, 2006 12:45 am |
Yes, you have to set at least one of the operands to floating-point type for the expression to evaluate as a floating-point result. You were only converting the number to floating-point after it already did the integer division. It's a common mistake, especially among non-programmer types, because your calculator will just automatically convert them for you (and that's because the calculator assumes all numbers are floating-point).
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sat Dec 02, 2006 9:22 am |
To make it even clearer you need to do something like this. #show (%float(@health)/%float(@maxhealth))
|
|
_________________ Asati di tempari! |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|