Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Tirin
Newbie


Joined: 13 May 2003
Posts: 4
Location: Australia

PostPosted: 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.
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: 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
Reply with quote
Tirin
Newbie


Joined: 13 May 2003
Posts: 4
Location: Australia

PostPosted: 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
Reply with quote
LightBulb
MASTER


Joined: 28 Nov 2000
Posts: 4817
Location: USA

PostPosted: 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
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net