$percent

By ^Neptune on Aug 24, 2008

A really really simple custom alias, but this can cut down on a lot of calculations.

$percent(N,C)
Returns how much percentage N is of C.

Properties:
  suf         Appends the percentage sign to the end of the value

Examples:
               //echo -a $percent(2,10)
               //echo -a $percent(8,24).suf

Tips:
If you're using any number identifiers on the text such as $int or $round, you shouldn't use the .suf property.

If you manage to get a recurring percentage number such as 33.3333 recurring, $percent will return a maximum of 6 digits after
the decimal point.
alias percent {
  if ($isid) {
    if (!$1) && (!$2) { return $null }
    else {
      if (!$prop) { return $calc($1 / $2 * 100) }
      if ($prop == suf) { return $calc($1 / $2 * 100) $+ % }
    }
  }
}

Comments

Sign in to comment.
^Neptune   -  Aug 27, 2008

Woah, that's certainly been shortened there D:

 Respond  
Eugenio   -  Aug 24, 2008

lmaoooo

 Respond  
EL   -  Aug 24, 2008

Rofl Typo? ;o cant be...maybe napa? nah couldnt be! oh oh its zmodem?!?!?! rofl wtf.Nice tatt btw ;p

 Respond  
Zmodem   -  Aug 24, 2008

You don't need your 'else' statement. mIRC will automatically keep going in the case of the 'if' statement being false. You also don't need to 'return $null' as 'return' in general gives an empty (or $null) returned value when no other value is specified.

Another tip I can give you is that if you check that '$prop == suf' before anything, you can deduce that you can return the value with the proper suffix. Otherwise, the very next line is done (returning with no suffix) based on the fact that the 2 proper comparisons have already been made, saving you space and time for coding.

You also do not need the second 'if' statement that makes sure the values are $null then returns. Just compare all of the things you want 'true'.

Note: Appending extra braces when comparing multiple operands at a time, ie: if ((!$1) && (!$2)), makes the parser run quicker.

NEW: I forgot to mention the power of $iif() :-)

alias percent $iif(($isid) && ($1) && ($2),return $calc($1 / $2 * 100) $+ $iif($prop == suf,%))

Hope this helps you! :-)

 Respond  
EL   -  Aug 24, 2008

;o /me tests;p

 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.