|
Loftaris Adept
Joined: 24 Aug 2004 Posts: 277
|
Posted: Wed Jun 17, 2009 11:20 pm
Why can't I calculate percentage |
I'm using Cmud 3.08, and for the life of me I just cannot calculate a percentage.
The bar I want to trigger is this:
{F:At} B: 1/56% GTNL: 8357352 LAST: 297 SKILLS: 6291085 (TH)
My trigger is set up for this:
GTNL: (%d) LAST: (%d) SKILLS: (%d)
And well I've somewhat butchered the trigger but it looks SOMETHING like this:
#var g2n %1
#var skillgxp %3
#math gxperc %format(3,(@g2n)/(@g2n+@skillgxp))
#sub {G2N: %format(3, (@gxperc))~% Last: %2 Skills: %3}
It was working until the number changed, now it doesn't work anymore. I had to add the %format to allow for the decimal, but that's not working anymore. Why can't I just simply have it calculate the number, it always returns 0 instead of .85 (85%)
Anyone help please? |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Jun 18, 2009 12:59 am |
You need to use %float. Otherwise, CMUD returns a rounded value instead.
#MATH gxperc %float(%1)/(%1+%3) will work.
Alternatively, you can multiply the result by 100 to get the answer, too.
Charneus |
|
|
|
Loftaris Adept
Joined: 24 Aug 2004 Posts: 277
|
Posted: Thu Jun 18, 2009 1:03 am |
I tried *100, but since it already returned 0 it didn't work :(
Thanks, %float worked. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Jun 19, 2009 5:28 pm |
You can get it to work by multiplying by 100, as Charneus suggested. To do this, you have to do the multiplication before the division. It is the division that ends up rounding. So:
#MATH gxperc (%1 * 100)/(%1+%3) |
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Fri Jun 19, 2009 6:23 pm |
...but beware if (%1 * 100) will exceed 32-bit limit for integer values. I've noticed your GNTL value is relatively big, so this may an issue for you.
|
|
_________________ 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 |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Jun 19, 2009 6:43 pm |
Actually, CMUD performs most of it's intermediate calculations using 64-bit integers these days, so it shouldn't be a problem.
|
|
|
|
Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Fri Jun 19, 2009 7:27 pm |
Heh, I used almost the same expression in my own script 1,5 years ago and hit the 32-bit limit with easy. Here is my old thread: http://forums.zuggsoft.com/forums/viewtopic.php?t=28501 Reading your explanation there I doubt that this problem can be easily fixed, better leave it "as is".
|
|
_________________ 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 |
|
|
|
|
|