mIRC Homepage
Posted By: MetallicAchu A comma generator - 13/04/04 12:47 PM
The script turnes 10000 to 10,000

Personally I think it's useful, and hope it'll appear in the next version.

addpsik {
if ($1 == $null) { halt }
if ($1 isnum) {
if ($len($1) <= 3) { return $1 }
else {
unset %tempfinish
set %temp $1
while ($len(%temp) > 3) {
set %tempfinish $right(%temp,3) $+ , $+ %tempfinish
set %temp $left(%temp,$calc($len(%temp) - 3))
}
set %tempfinish %temp $+ , $+ %tempfinish
set %tempfinish $left(%tempfinish,$calc($len(%tempfinish) - 1))
return %tempfinish
}
}
}
Posted By: starbucks_mafia Re: A comma generator - 13/04/04 01:30 PM
You can use $bytes(number, b) to do this already (although admittedly it's not it's intended purpose). For example:
//echo -a $bytes(10000, b) echoes 10,000
Posted By: MetallicAchu Re: A comma generator - 13/04/04 04:12 PM
Always nice to learn about new commands, thanks!

Didn't know it exists when I searched for it, so had to build one for myself.
Posted By: Soul_Eater Re: A comma generator - 13/04/04 10:25 PM
i personally lik the key next to the 'm' key crazy
Posted By: LocutusofBorg Re: A comma generator - 14/04/04 03:20 PM
new? $bytes has been around for ages smile
Posted By: tidy_trax Re: A comma generator - 14/04/04 04:04 PM
I think he meant it's new to him
Posted By: FiberOPtics Re: A comma generator - 15/04/04 10:39 AM
Hi,

that $bytes suggestion by starbucks is good, though it has problems when using decimals or negative numbers.
For example: $bytes(0.4,b) will return 0, or $bytes(5.8,b) will return 6, or $bytes(-100,b) returns -,100

This alias will cover any number, whether it is decimal, negative, or near zero:

Code:

alias commas { 
  var %min = $iif($left($1,1) == -,-)
  tokenize 46 $abs($1) 
  return $+(%min,$bytes($1,b),$iif($2,.),$2))
}

Usage: $commas(number)

Grtz
© mIRC Discussion Forums