Commas

By RusselB on Jun 08, 2005

returns a number formatted with commas representing the standard thousands, millions, billions separations in a number

usage: /comma number or $comma number

Updated to account for updated knowledge. Also allows for decimals in the number.

alias comma {
  $iif($1 !isnum,echo -a Number required,$iif($isid,return,echo -a) $+($bytes($int($1),b),$calc($1 - $int($1))))
}

Comments

Sign in to comment.
Scakk   -  Sep 28, 2007

I am still getting the same error with the updated code.

 Respond  
RusselB   -  Sep 28, 2007

Thanks Scakk for catching the missing bracket.
Regarding the extra 0, that\'s due to the mis-placement of the bracket that was missing. My code has been updated.

 Respond  
Scakk   -  Sep 28, 2007

Forgot code tags _

alias comma {
$iif($1 !isnum,echo -a Number required,$iif($isid,return,echo -a)) $+($bytes($int($1),b),$calc($1 - $int($1)))
}
 Respond  
Scakk   -  Sep 28, 2007

First there was an error when using it to sart with. There was a \" ) \" missing.

alias comma {
$iif($1 !isnum,echo -a Number required,$iif($isid,return,echo -a)) $+($bytes($int($1),b),$calc($1 - $int($1)))
}

When I added the missing \" ) \" it did not work right. It added a \" 0 \" to the end of every number. Examples below.

/comma 5 -> 50
/comma 50 -> 500
/comma 500 -> 5000
/comma 5000 -> 5,0000

 Respond  
RusselB   -  Jan 07, 2006

Ooops..Nice catch FibreOptics...When I changed the code, I forgot to change the description

 Respond  
FiberOPtics   -  Jan 04, 2006

bearruler, try these:

$bytes(0.5,b) -> 1
$bytes(-100,b) -> -,100
$bytes(10000000.1234,b) -> 10,000,000
$bytes(99999999999999999,b) -> 100,000,000,000,000,000

You were saying?

 Respond  
FiberOPtics   -  Jan 04, 2006

There is an error in the description, where it says it works with atleast 50 numbers. Try this:

//echo -a $bytes(99999999999999999,b)

Result: 100,000,000,000,000,000

$bytes has trouble with rounding at 16 digits, and over 17 it start screwing up severly.

Try:

//echo -a $bytes(10000000000000000000000000,b)

Result:

10,000,000,000,000,001,000,000,000

See that 001 in the forth to last trio of digits?

That\'s why I made that $comma identifier, it gives support for an unlimited amount of numbers, as long as it\'s within the string too long limit.

 Respond  
xDaeMoN   -  Jun 15, 2005

Yes it does put commas in it but not if the number has decimals.

 Respond  
bearruler   -  Jun 14, 2005

Its a great script, but i just found this:
$bytes(NUMBER,b) does the same this with no hassle =P
I spent hours making my own, when $bytes(100000000000,b) gives me 100,000,000,000. Nice script, but with the $bytes, its unnecessary

Bear

 Respond  
Stealth   -  Jun 11, 2005

nice script

 Respond  
QuickStep   -  Jun 10, 2005

meaning this is the way to go
alias comma {
var %comma = $1, %c
while %comma {
%c = $+($right(%comma,3),$chr(44),%c)
%comma = $left(%comma,-3)
}
return $left(%c,-1)
}

 Respond  
QuickStep   -  Jun 10, 2005

general nice code, a few tips though: the variable %b isnt needed, you can just paste that into %c. Also (and this is something to keep in mind) dont double VAR a variable (this also means, dont use VAR in a loop). declare all the vars in the beginning like:
var %comma = $1, %c
and dont use any more var commands

anyway good work

 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.