|
ew1075 Newbie
Joined: 21 Sep 2007 Posts: 4
|
Posted: Mon Sep 24, 2007 9:08 am
#MATH command rounding decimals. |
Here is a simple version of what I have set up:
#MATH answer 5/2
This should set the variable @answer equal to 2.5. Instead it removes the decimal and rounds down, leaving the variable equaling 2 instead of 2.5.
Is there any other command, or any functions i can use, that will keep the decimal on the number? I know how to use the %format function to display
the decimals, but the problem is my variable never has a decimal because the #MATH command is automatically rounding down.
Thanks in advance for the help! |
|
|
|
eclpmb Novice
Joined: 29 Feb 2004 Posts: 36 Location: United Kingdom
|
Posted: Mon Sep 24, 2007 9:55 am |
will put 2.5 in answer (tested with zMud 7.21)
Make sure your maths starts with floating point and it should stay floating point. Try adding 0.0 to a variable, and so on. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Sep 24, 2007 11:23 am |
You can also use the %float function to make a number a float.
|
|
|
|
Guinn Wizard
Joined: 03 Mar 2001 Posts: 1127 Location: London
|
Posted: Tue Sep 25, 2007 3:12 am |
It's worth adding that I think 5/2 producing an integer result is standard [correct] in a number of languages. As eclpmb mentioned, using 5.0/2 tells zMud that you're looking for a Float rather than an Int, or using %float works too. But it's not uncommon that 5/2 = 2 really.
|
|
_________________ CMUD Pro, Windows Vista x64
Core2 Q6600, 4GB RAM, GeForce 8800GT
Because you need it for text... ;) |
|
|
|
jtown84 Novice
Joined: 09 Oct 2007 Posts: 36
|
Posted: Tue Oct 09, 2007 8:29 am |
Quote: |
#al {calc} {#show %ansi( high, green)%1 %ansi( high, white)~= %float( %eval( %1))}
|
Thats what i have, and say i do calc 5/2 it now = 2.0 :( |
|
_________________ Aardwolf |
|
|
|
eclpmb Novice
Joined: 29 Feb 2004 Posts: 36 Location: United Kingdom
|
Posted: Tue Oct 09, 2007 10:12 am |
That's because you're doing the calculation as integer and turning the result into a float.
calc 5/2 does %float (5/2) - it works out the value in the brackets and then turns it into a float. You can't just wrap the expression in %float you need %float(5)/2 |
|
|
|
Dharkael Enchanter
Joined: 05 Mar 2003 Posts: 593 Location: Canada
|
Posted: Tue Oct 09, 2007 10:21 am |
#al {calc} {#show %ansi( high, green)%1 %ansi( high, white)~= %eval( %subregex( "%1", "((?<!\.)\b[0-9]+(?!\.([0-9]+\b)?|\.[0-9]+\b))", "%float(%%1)"))}
|
|
_________________ -Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style." |
|
|
|
|
|