|
Tirin Newbie
Joined: 13 May 2003 Posts: 4 Location: Australia
|
Posted: Tue May 27, 2003 5:02 am
decimal places? |
I've been trying to make myself a script that will show percentages of hitpoints, etc. and have stumbled across this obstacle. As far as I can tell, #MATH won't return anything other than a whole number.
ex: #MATH cheese (3 / 4)
This should set cheese to .75, but actually sets it to 0.
Is there any way to get around this? Another command, or changing the type of the variable or something? I'm at a loss. |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue May 27, 2003 5:34 am |
That's correct, zMUD was designed to use integers. Recent versions have added limited support for floating point numbers (see the %float function), but it's still best to stick to integers whenever possible. For percentages, that just means doing the multiplication first.
3/4 = 75%
#MATH cheese (3 * 100)/4
will set @cheese to 75, which is correct for percentage.
LightBulb
Advanced Member |
|
|
|
Tirin Newbie
Joined: 13 May 2003 Posts: 4 Location: Australia
|
Posted: Tue May 27, 2003 7:52 am |
Yeah, I'd played with multipying by zeros, but in reality my equations are more like 342/389 :/ That's heaps o' decimals.
Thanks, I'll check out %float |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Tue May 27, 2003 9:12 am |
The formula for percentage is always the same. If a is x% of b, then x = (a * 100)/b. It works just as well with 342/389 as it does with 3/4.
LightBulb
Advanced Member |
|
|
|
|
|