|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: 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 |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: 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 |
|
|
|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: 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 |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: 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) |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
nexela Wizard
Joined: 15 Jan 2002 Posts: 1644 Location: USA
|
Posted: Tue Jan 26, 2010 10:45 pm |
ooops yeah what MattLofton said. I shoulda pay more attention to mmmmm coookie
|
|
|
|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: Wed Jan 27, 2010 12:42 am |
thats great thankyou. both have actually been useful for me.
|
|
|
|
adamandkate Wanderer
Joined: 14 Oct 2009 Posts: 57
|
Posted: 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) |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: 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 |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Thu Jan 28, 2010 12:00 pm |
#IF (@Var>%int(@Var)) {var=(%int(@var)+1)}
|
|
_________________ Discord: Shalimarwildcat |
|
|
|
|
|