$padnum()

By knoeki on Jun 29, 2009

Once again, I\'m back with another custom identifier.

I wrote this just because I happened to need this a few times.

It doesn\'t do much, but what it does do, it does right. (confused yet? :_)). It takes two numbers, a low and a high, and returns the low number prefixed with as many zeros as needed to get the same length as the high number. purely for visual pleasure when making long numbered lists or something like that, since it will align nicely.

Usage:
$padnum(low, high, )

if you specify \'s\', it will add the zeroes to the end, rather than in front.

alias padnum {
   if ($3 == s) {
      return $+($1,$str(0, $calc($len($2) - $len($1))))
   }
   else {
      return $+($str(0, $calc($len($2) - $len($1))),$1)
   }
}

Comments

Sign in to comment.
Jonesy44   -  Jun 29, 2009

Just for reference, check out $base too, it\'s helpful for the same function however using it can be quite tricky this simplifies it a hell of a lot. Here\'s a slightly shorter version for you :)

alias padnum return $+($iif($3 == s,$1),$str(0, $calc($len($2) - $len($1))),$iif($3 != s,$1))
 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.