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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Aselarin
Beginner


Joined: 23 Jul 2005
Posts: 26

PostPosted: Thu Dec 13, 2007 8:37 pm   

Percent calculations
 
i was wonder if there is a way to make floating point numbers show with only 2 decimals ?
or is there another way to do this without %float ?
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Dec 13, 2007 8:46 pm   
 
If you are looking to do a perctage display for 0 to 99 percent then I would suggest using integer math for better speed. This is done by multiplying first then dividing. ie (79*100/97 would give a percentage for 79/97)

You can also use %float and %format if you need a more options, but generally anything can be done with integer math with just as much precision.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Arde
Enchanter


Joined: 09 Sep 2007
Posts: 605

PostPosted: Thu Dec 13, 2007 8:52 pm   
 
Be aware though when multiplying first that after multiplication internal value must not exceed 32-bit limit for integers.
_________________
My personal bug|wish list:
-Wrong Priority when copy-paste setting
-1 prompt trigger for Mapper, Session and General Options, not 3 different!
-#SECTION can terminate threads
-Buttons can't start threads
Reply with quote
Aselarin
Beginner


Joined: 23 Jul 2005
Posts: 26

PostPosted: Thu Dec 13, 2007 9:02 pm   
 
i'm using this trigger just to calculate how much percent of which kind i'm doing.
put the variable as integer, and now it's accurate, but it got like 10 decimals. any way to reduce it ? i mean like when i have the percent value put into an emote or such,
looks really stupid with 10 decimals, 2 would do just fine
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Dec 13, 2007 9:04 pm   
 
%format is what you're after

From the help examples, #SHOW %format(2, 1.23456)
would show 1.23
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Aselarin
Beginner


Joined: 23 Jul 2005
Posts: 26

PostPosted: Thu Dec 13, 2007 9:13 pm   
 
the example worked fine, but when applied to variable it didn't quite work out.
#var meleepercent gives me Variable: + meleepercent (Integer) 86.4864864864865
#show %format(2,@meleepercent) gives me 86.00

nm this reply, got it working now, had the variable set to integer, but trying to handle it as floating point with %format
Reply with quote
Guinn
Wizard


Joined: 03 Mar 2001
Posts: 1127
Location: London

PostPosted: Thu Dec 13, 2007 9:24 pm   
 
Ah, try doing
%format(2, (%1 * 100.00 / %2))

(replacing the %1 and %2 where appropriate)
putting the .00 after multiplying by 100 forces it to be a decimal not int
_________________
CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;)
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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