$formatnr for mIRC

By Vegito on Jun 24, 2015

Syntax:
$formatnr(N, zeropad)

Examples:
$formatnr(3, 2) // returns 03
$formatnr(13, 3) // returns 013
$formatnr(05, 1) // returns 5

alias formatnr {
  var %nr = $1, %zeropad = $2

  if (%zeropad == 1) {
    var %formattedNr = $iif($len(%nr) == 1 || %nr !isnum 0-9, %nr, $right(%nr, 1))
  }
  else { 
    var %formattedNr = $iif(%zeropad > $len(%nr), $str(0, $calc(%zeropad - $v2)) $+ %nr, %nr)
  }    

  return %formattedNr
}

Comments

Sign in to comment.
Wims   -  Jun 24, 2015

Hey, $base already has a function for this, for example $base(N,10,10,zeropad)

Vegito  -  Jun 25, 2015

Ah, thanks! Seems like I was using $base() wrong way before :P

Sign in to comment

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.