$percent

By Noutrious on May 23, 2009

Just had a problem with percent getting when the first number is bigger than the second.
Solved the problem by making an aliases for that and here it is, may be pretty handy for some of you guys.

Syntax: $percent(x,y,round).suf or /percent x y round
Examples:

  • $percent(6,1).suf | 83.333333%
  • $percent(6,1,2).suf | 83.33%
  • $percent(6,1,2) | 83.33
  • $percent(1,6,2) | 16.67

This is the maximum functionality that could be needed and it's only one line. :)

alias percent $iif($isid,return,echo -at) $round($iif($1 > $2,$calc(100 - $calc($iif($1 > $2,$2 / $1 * 100,$1 / $2 * 100))),$calc($iif($1 > $2,$2 / $1 * 100,$1 / $2 * 100))),$iif($3,$v1,15)) $+ $iif($prop = suf,$chr(37))

Comments

Sign in to comment.
Noutrious   -  May 25, 2009

Folks, c'mon..

  23:15:05    Detailed | [visits|ratio:4.45(j:77.53% p:22.47%)] [lines|ps:220.88 ph:9.2 pd:0.15]
It's ment for things like in here.

 Respond  
tv3636   -  May 23, 2009

Even so, what does 83% have to do with that?
And why would you want it to limit to 100%? If something is over 100% it's over 100%, not 83% :\

Oh I see, 1/6 = 16.66666% so somehow that translates to 83.3333%

Still..that's kind of a weird way of dealing with a case that shouldn't necessarily be dealt with.

 Respond  
Noutrious   -  May 23, 2009

What's not to understand? It limits percents to 100.

 Respond  
FordLawnmower   -  May 23, 2009

I'm lost on this too ;/ % is found by (a / b) * 100. Where the question is "What Percent of b is a?" 6 is 600% of 1 ;/ Not 83%.
It's just a fraction 6/1.

 Respond  
Noutrious   -  May 23, 2009

This snippet limit's percents to 100%.

 Respond  
Firstmate   -  May 23, 2009

I don't get how percents are different when the first number is bigger...
All it means is the percentage will be greater than 100%...

Or how in any way, $percent(6,1) can be 83%

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.