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
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Tue Jan 26, 2010 3:54 pm   

basic help with #math
 
if i run in cmud...

#math value (35000\%1)*100

where %1 = 56000

the answer is returned as 3500000

if i do it on a calculator the answer is 62.5

any idea what this is about?

also is there a way to round a number up. or round a number in a variable up

thanks
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Jan 26, 2010 5:06 pm   
 
First, you have \ which is the %mod operator and not the division operator. I think you want to use / for division.

Second, CMUD does not perform floating point math by default. To force floating point, you need to add a decimal .0 to your first number, or use the %float command. So your correct command would be:

#MATH value (35000.0/%1)*100

also, you don't really need the #MATH command anymore. That just remains left over from zMUD compatibility. The better way to do this is just:

value = (35000.0/%1)*100
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Tue Jan 26, 2010 5:43 pm   
 
thats great. thanks for that. anyone able to tell me how to round a whole number up inside a variable? eg 2.24242 becomes 3.

thanks
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Jan 26, 2010 6:01 pm   
 
There's no built-in function for that.

#function roundup($value) {
#if (%pos(".",$value)) {$value = %left(@value,(%pos(".",@value) - 1))}
#return $value
}
_________________
EDIT: I didn't like my old signature
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Jan 26, 2010 10:25 pm   
 
Or Format it to a 0 decimal point floating number and it will automaticly round


%format("&0.0f",$value)
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Jan 26, 2010 10:41 pm   
 
%format uses normal rounding rules, so 2.4 becomes 2 rather than 3.
_________________
EDIT: I didn't like my old signature
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Jan 26, 2010 10:45 pm   
 
ooops yeah what MattLofton said. I shoulda pay more attention to mmmmm coookie
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Wed Jan 27, 2010 12:42 am   
 
thats great thankyou. both have actually been useful for me.
Reply with quote
adamandkate
Wanderer


Joined: 14 Oct 2009
Posts: 57

PostPosted: Thu Jan 28, 2010 5:47 am   
 
when making my own function that way how would i use it?

ive tried the usual way to use functions without much luck eg #say %roundup(@myvar)
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Jan 28, 2010 6:08 am   
 
use @ instead of %. % is reserved for functions (and wildcards/variables) that Zugg creates as part of the zscript definition.
_________________
EDIT: I didn't like my old signature
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4254
Location: Pensacola, FL, USA

PostPosted: Thu Jan 28, 2010 12:00 pm   
 
#IF (@Var>%int(@Var)) {var=(%int(@var)+1)}
_________________
Discord: Shalimar#3679
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