mIRC Home    About    Download    Register    News    Help

Print Thread
#229472 06/02/11 02:32 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Hey guys, how would you do this?

for example 12345 will become 12,345 and 1123 would become 1,123

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
$bytes(number,bd)


I am SReject
My Stuff
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Thanks froggie!

Does anyone know of the algorithmn that does it? I think what I'm asking is what is behind the $bytes function

Last edited by pouncer; 06/02/11 02:50 PM.
Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
you could probably do it like
Code:
alias commas {
  var %in = $remove($1-,$chr(44))
  if (%in !isnum) { return }
  return $regsubex(%in,/\G((?:^-)?\d\d?\d?)(?=(?:\d\d\d)+(?:\.\d+)?$)/g,\t $+ $chr(44))
}



Note: this will also fix commas in a Number.
Ie: 1,26,4564 would be returned as 1,264,564


;Edited to improve regex to allow for decimals

Last edited by FroggieDaFrog; 06/02/11 03:26 PM.

I am SReject
My Stuff
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
Thanks again Froggie, but I'm not too advanced in regex, what is it actually doing?

What is the algorithmn behind it that adds the commas?

Thanks in advance

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
We are getting no where fast, huh?
What do u mean "algorithrum"?

I guess one way to do it would be:
1) to find the decimal place(if not one, tack one on)
2) loop backwards 3 positions
3) add comma
4) continue until no nummbers are left


I am SReject
My Stuff

Link Copied to Clipboard