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
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Thu May 01, 2008 9:11 am   

Math Question, decimal truncated, want to see up to 2 decimal places
 
Some math, should add up to 640 and in the end show a value of 6.40 or 6.4 but it does not, instead it shows a value of 6
Code:
#alias testmath {eq_mystats=0.00;eq_mystats=(@eq_mystats+(100*0.5*2));eq_mystats=(@eq_mystats+(100*1*3));eq_mystats=(@eq_mystats+(100*0.4*3));eq_mystats=(@eq_mystats+(100*0.2*6));#show (@eq_mystats/100)}


How do I need to do my math so that I am able to see the decimal up to 2 places
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Thu May 01, 2008 9:21 am   
 
OK strange the above example works but this one does not:

Code:
#alias testmath2 {eq_mystats=(640*1.00);#show (@eq_mystats/100)}
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu May 01, 2008 9:35 am   
 
Interesting. Neither %float nor %format work like they say they are supposed to.
Reply with quote
oldguy2
Wizard


Joined: 17 Jun 2006
Posts: 1201

PostPosted: Thu May 01, 2008 9:43 am   
 
Code:
eq_mystats=%float(640*1.00)


Works
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Thu May 01, 2008 9:44 am   
 
well ive found a work around for the time being. change the variable type from auto to float type.. kinda annoying but it works.
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Thu May 01, 2008 9:58 am   
 
You're either always going to care about the decimal of a particular number or you never will, so just use %float for those numbers that you care about.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Thu May 01, 2008 4:29 pm   
 
Doing:

#show (@eq_mystats/100.0)

will also work. If the variable is set to auto-type, then CMUD only does floating-point math if you specifically put the decimal point on the numbers (like 100.0).
Otherwise you have to set the variable to be a Float type as you mentioned.
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