Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Sat Sep 24, 2005 8:08 am   

%eval problem holding 0.X values
 
Most of the scripts I write are designed to track statistics and averages. One of the most common formulae in all of my scripts is:
Code:
#var qbonusta {%eval( @qbonust/@qcompleted).%eval( (( @qbonust\@qcompleted) * 100)/@qcompleted)}
The variables and so change of course, but that's the basic formula. There's a flaw in the formula though; of the result is XX.0X, it drops the 0 and displays it as XX.X. This is because I am treating it as 2 seperate numbers, rather than one whole number; yet I've never been able to get zmud to show me decimal answers using #math or %eval with any other formula. Is there any way to create a better formula, that will show me the anwer to 2-3 decimal places (no more), and accurately?
Reply with quote
Slaem
Apprentice


Joined: 20 Sep 2005
Posts: 135

PostPosted: Sat Sep 24, 2005 12:20 pm   
 
#VAR qbonusta {%concat( %eval( @qbonust/@qcompleted), %if( %len( %eval( (@qbonust*100/@qcompleted)/@qcompleted))<2, %insert( ".0", %eval( (@qbonust*100/@qcompleted)/@qcompleted), 1), %insert( ".", %eval( (@qbonust*100/@qcompleted)/@qcompleted), 1)))}

Used Pretty Print
Syntax Colourizer

I wasn't sure what your variables would look like. But after testing it with small numbers and moving the location of the *100 I think this worked. For example, with 4 and 5 it returned 0.16. With 2 and 5 it returned 0.08. Hope it does what you need. Very Happy
_________________
Show your love.
Support Zugg Software!
Donate to zugg@zuggsoft.com with PayPal Send Money.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sat Sep 24, 2005 2:04 pm   
 
#VAR qbonusta {%eval(@qbonust*100/@qcompleted)}
#VAR qbonusta {%insert(".",@qbonusta,%eval(%len(@qbonusta)-2))

It is much shorter this way.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Sat Sep 24, 2005 8:01 pm   
 
At this moment, the current variable values are:
Code:
#var {qbonust} {49}
#var {qcompleted} {637}
Slaem, your formula is giving me a value of 0.00 every time. Vijilante, I had to add a } at the end of the 2nd variable to make it work (I assume that just fixes a typo, but mention it just in case), and yours returns 0.7 every time.... I'm looking for a formula that will return 0.07 on that equation, with these particular numbers. The entire alias that they are in:
Code:
#VAR qptav {%eval( @qpointsrt/@qcompleted).%eval( (( @qpointsrt\@qcompleted) * 100)/@qcompleted)} _nodef {GroupInfo|Questing}
#VAR qpgpc {%eval( @qgoldrt/@qcompleted).%eval( (( @qgoldrt\@qcompleted) * 100)/@qcompleted)} _nodef {GroupInfo|Questing}
#math qendta {(@timeqct)/(@qcompleted)} {GroupInfo|Questing}
#math qendmta {(@qendta)/60} {GroupInfo|Questing}
#math qendsta {(@qendta) - ((@qendmta)*60)} {GroupInfo|Questing}
#var ttqpbonusa {%eval( @ttqpbonus/@qcompleted).%eval( (( @ttqpbonus\@qcompleted) * 100)/@qcompleted)} _nodef {GroupInfo|Questing}
#var qbonusta {%eval( @qbonust/@qcompleted).%eval( (( @qbonust\@qcompleted) * 100)/@qcompleted)} _nodef {GroupInfo|Questing}
#math perqavt {(@qpointsrt + @qbonust) + (@qcompleted * 2) + (@lqtb * @qcompleted)} {Groupinfo|Questing}
#var perqav {%eval( @perqavt/@qcompleted).%eval( (( @perqavt\@qcompleted) * 100)/@qcompleted)} _nodef {GroupInfo|Questing}
Below that is the output info... I doubt the whole alias was needed, but *just in case* since I assume you both gave me formulas that should work... :P
Reply with quote
Slaem
Apprentice


Joined: 20 Sep 2005
Posts: 135

PostPosted: Sun Sep 25, 2005 6:13 am   
 
They're both working properly.

Vij's evaluated (49*100)/637 = 7. It then inserted the "." in front. (needs to add ".0" if length < 2)

Mine first evaluated 49/637 = 0.07, which evals to 0.
It secondly evaluated (49*100/637)/637) = 0.01, which also evals to 0.
It then evaluated 0 is < 2 digits in length, added ".0", and concated them to 0.00.

I missed that you were going for the modulus. I had written them as divisions. But since I moved the *100 they return the same results. Are the formulae you are using correct?
_________________
Show your love.
Support Zugg Software!
Donate to zugg@zuggsoft.com with PayPal Send Money.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Sep 25, 2005 2:23 pm   
 
You original use of the modulus operator suggested to me that you would be seeing values greater then 1. It is quite simple to deal with this.

#VAR qbonusta {%concat("00",%eval(@qbonust*100/@qcompleted))}
#VAR qbonusta {%insert(".",@qbonusta,%eval(%len(@qbonusta)-2))}

If you are going to be tracking data for long periods of time it is possible for this formula to fail as @qbonust approaches 1% of the integer limit roughly 240 million. From the values you have supplied I do not see that as being very likely.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Mon Sep 26, 2005 10:49 am   
 
Hrmm not actually sure what modulus means :P Here's an examples of where I may use that formula:

In a quest tracking script, to track qps/quest (such as in the above). I use it to divide qps earned by total quests. The number could be 100 quests and 1500 qps, and I'd want the output as "15" or "15.00" But if it was 100 quests and 1526 qps, I'd want "15.26" -- my formula works for both, but in a third example, it could be 100 quests for 1506 qps .. instead of displaying 15.06, it displays 15.6. Because the formula I am using does 2 math equations -- one for the integer, one for the decimal, it returns the second result as 06, then drops the 0, in the above example.

The problem with the second formula you gave mem vijilante, if that it always returns at 0.(X). So if it's 29 quests and 2 qps, it returns correctly 0.06 (should be 0.07, as the actual number is 0.689xxxx, but close enough). But now if it's 29 quests, 50qps, it returns 0.172 instead of 1.72 (because of the %concat). I'm looking for an equation that will always return the actual value out to 2-3 decimal spots.

My apologies if I didn't make this clear in my original post. Slaem's first suggestion appears to work, once I make the numbers larger (as he said above). In the majority of the scripts I use this formula in, the result returned will have a number between 3.7 and 1000 (various scripts). The only exception to this (but the one that matters the most, because the number is so small) is the stuf I posted in the original post. That evaluates "lucky bonus" qps, and generally will involve very small numbers.

Is there a simpler way to do this, just using the %float command? I have tried (amongst other things) using %float in this several times, and I cannot seem to get it to work right. However, I know I used %float once in the past (a long time ago) to get a similar result. Unfortunately, I no longer

I went back and re-tried everything you guys have posted. Slaem's original string, when working with large numbers, is pretty much what I was looking for, but on smaller numebrs the return of 0.00 is not :/

Thanks a lot for the help with this :)
Reply with quote
Vitae
Enchanter


Joined: 17 Jun 2005
Posts: 673
Location: New York

PostPosted: Mon Sep 26, 2005 3:02 pm   
 
See if this works

#ALIAS lquest {
#MATH qptemp ((@totalqp*100)/@totalquests)
#MATH averageqp (@qptemp/100)
qpfloat=%mod( @qptemp, 100)
#IF (@qpfloat < 10) {qpfloat=%concat( "0", @qpfloat)}
%1 ~@Rquest:~@G @questmob ~(@questarea)~@M time: @questlength~@C reward: @questreward@tierbonus@doubleqp@questbonus~+2~=%eval( @questreward@tierbonus@doubleqp@questbonus+2)qp@questpracs@questtrains@questtp~@Y average: @{averageqp}.@{qpfloat}qp/quest over @totalquests quests.~@w
}
_________________
http://www.Aardwolf.com
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon Sep 26, 2005 8:24 pm   
 
I remember one set of formulas I used that ran a series of #IF checks on the size of numbers it was working with and then used a formula most suited to give the best precision. I don't personally support the use of %float since it often returns numbers with unacceptable inaccuricies. What I have written is a quick and dirty formula that assumes a specific range in the numbers, in both cases. In the latter case this should actually be:
#VAR qbonusta {%concat("00",%eval(@qbonust*100/@qcompleted))}
#VAR qbonusta {%insert(".",@qbonusta,%eval(%len(@qbonusta)-1))}
This is because %len returns the total length ("12345" returns 5) then %insert puts the character at the specified point ans pushe the rest back (%insert(".","12345",4) returns "123.45". So there was an error in my formula.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Slaem
Apprentice


Joined: 20 Sep 2005
Posts: 135

PostPosted: Tue Sep 27, 2005 8:14 am   
 
@Atreides_096, did you mean to divide by @qcompleted twice? That would explain the very small results evaluating to zero.

#VAR qbonusta {%concat( %eval( @qbonust/@qcompleted), %if( %len( %eval( (@qbonust*100/@qcompleted)))<2, %insert( ".0", %eval( (@qbonust*100/@qcompleted)), 1), %insert( ".", %eval( (@qbonust*100/@qcompleted)), 1)))}

Check out %round() for more accurate results.

Used Pretty Print
Syntax Colourizer
_________________
Show your love.
Support Zugg Software!
Donate to zugg@zuggsoft.com with PayPal Send Money.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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