Welcome

User: Pass:   register


;
; Author:    FiberOPtics - mirc.fiberoptics@gmail.com
;
; Usage:     $comma(<number>)
;
; Example:   $comma(10000000) returns 10,000,000
;             
;            The code will work correctly with negative numbers, and numbers with a decimal part.
;            If the input is not a valid number, then the input is returned in the same state.
;
; Reqs:      mIRC 5.91
;
; Install:   In mIRC: alt+r -> tab "Remote" -> paste code there
;
; Notes:     This snippet uses $regsub instead of the common way with $bytes because
;            $bytes is limited and has some issues:
;
;            $bytes(-100,b)   --> -,100
;            $bytes(1000.6,b) --> 1,001
;            $bytes(99999999999999999,b) --> 100,000,000,000,000,000
;                         
;            In other words, there are issues with negative numbers, rounding, and the length of
;            the number is limited. The first two issues could be worked around easily whilst still
;            using $bytes, however that won't help us with the problem of being limited to maximum
;            of 15 digits before things go wrong. Therefore I've opted to use a $regsub. 
;
;            Right now the code only allows for 1 optional "+" or "-" as first character in the digit.
;            In other words $comma(--1000000) will not be commatized. If you want to allow for multiple
;            signs then replace the first "?" in the pattern with a "*"
;

alias comma {
  var %a, %b = $regsub($ticks,$$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a)
  return %a
}






© 1996-2010 hdesk.org and dalnethelpdesk.com