mIRC Home    About    Download    Register    News    Help

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

$comma(23984897) = 23,984,897


Live to Dream & Dream for Life
#124175 03/07/05 07:50 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
$bytes(23984897,b) = 23,984,897

#124176 03/07/05 07:23 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#124177 03/07/05 10:05 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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


Gone.
#124178 04/07/05 09:13 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#124179 30/12/05 10:36 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
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



Gone.

Link Copied to Clipboard