mIRC Home    About    Download    Register    News    Help

Print Thread
#124174 03/07/05 07:05 AM
Joined: Apr 2004
Posts: 217
P
Fjord artisan
OP Offline
Fjord artisan
P
Joined: Apr 2004
Posts: 217
How about a $comma for numbers?
Would place a comma in the numbers.
Example:

$comma(23984897) = 23,984,897

#124175 03/07/05 07:50 AM
D
DaveC
DaveC
D
$bytes(23984897,b) = 23,984,897

#124176 03/07/05 07:23 PM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
If you want support for decimals ($bytes() cuts off the decimal part) you can make a custom identifier like this:
Code:
alias comma return $puttok($1,$bytes($1,b),1,46)

#124177 03/07/05 10:05 PM
Joined: Feb 2004
Posts: 2,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
Problem with that is that $bytes rounds off decimals.

$comma(0.9) would return 1.9, because it rounded 0.9 to 1, and did a $puttok transforming it into 1.9.

There's one other thing, and that is negative numbers will screw up, as $bytes(-100,b) returns -,100

Code:
alias comma {
  if ($1 !isnum) return 
  tokenize 46 $1
  return $+($iif(-* iswm $1,-),$bytes($abs($1),b),$iif($0 == 2,.),$2)
}

Anyway, you knew this already, but pointing it out still, and I'm sure you'll point something out too :tongue:

Greets

#124178 04/07/05 09:13 AM
Joined: Jan 2003
Posts: 2,125
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,125
Ah, I'd never noticed that $bytes(N,b) rounds numbers, I thought it only keeps the integer part. No good points left for me to add smile

#124179 30/12/05 10:36 PM
Joined: Feb 2004
Posts: 2,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
Anyway, $bytes has certain issues like rounding at more than 15 digits (try $bytes(99999999999999999,b)) so I decided to make a small snippet using $regsub that will take care of all these issues.

$comma



Link Copied to Clipboard