$comma()

By FiberOPtics on Jan 04, 2006

Author: FiberOPtics - mirc.fiberoptics@gmail.com


Usage: $comma()


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
}

Comments

Sign in to comment.
jaytea   -  Aug 26, 2017

hey man, sorry I missed you on IRC earlier! i hope life is treating you well and you've found other things to fulfill you as much as mIRC's fun little scripting language once did :D i myself have been off and on - mostly off - for the last 5 or so years, but came across a challenge on mirc.com's forums and decided to fire up mIRC again about a week ago. haven't /exit-ed yet! so it was quite a coincidence that you would show up now of all times, albeit not quite coincidental enough lol. there still seems to be a bit of interest in mIRC - even Sat is still around! we're on ##mirc on freenode, in case you find yourself on IRC again in another 7 years ;)

 Respond  
jaytea   -  Dec 27, 2010

FOptics ;') i remember when qwerty gave this to us as a challenge way back when. if you ever see this, come visit on IRC!

 Respond  
Ghost-writer   -  Oct 31, 2009

nice :) mirc.591?

 Respond  
FiberOPtics   -  Jan 04, 2006

Thanks for the info, atleast that helps. I still think it\'s kinda silly though.

 Respond  
xDaeMoN   -  Jan 04, 2006

Actually you can use html codes like
so you could have a new lines.

 Respond  
FiberOPtics   -  Jan 04, 2006

Thanks.

I was gonna submit all my snippets here, but I\'ve changed my mind. This \"Author\'s notes\" box doesn\'t respect any of the formatting that I had in my comments, and didn\'t even put newlines o.O making it one big chunk of text, something that looks really ugly, and makes it hard to read the comments. Comments are an important part of my snippets, and in its current state they are unreadable.

 Respond  
xDaeMoN   -  Jan 04, 2006

Very nice FiberOptics.

 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.