mIRC Home    About    Download    Register    News    Help

Print Thread
#144635 12/03/06 06:42 PM
Joined: Feb 2006
Posts: 95
B
blk Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Feb 2006
Posts: 95
I made a calc script that understands k as 000 and then returns 000 and k...
but is there a way to make like 743298 return 743k (rounded)
and like 2850372 return 2.85M (for million)


-blk-
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
/help $bytes

Joined: Feb 2006
Posts: 95
B
blk Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Feb 2006
Posts: 95
ook, thats one big headache...
How about, how do I make commas in it?


-blk-
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
assume %value holds the value

$bytes(%value,b)

** amazing **

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
$bytes could theoretically be what you want, however it doesnt treat K as 1000, but as 1024 :S similarly, 1G = 1024K etc. it even adds commas, but at the same time doesnt handle really long numbers ;P

this code isnt too tested, but i tried to make it support extremely large input, so i had to pretty much remake /inc smile

Code:
alias hi! {
  if ($2) {
    var %n = $replace($2,T,12,G,9,M,6,K,3)),%x = $iif($left($1,- $+ %n),$v1,0),%r = $right($1,%n)
    if ($mid($1,- $+ %n,1) > 4) %x = $regsubex(%x,/([^9]?)(9*?)$/,$calc(1+ \1) $+ $str(0,$len(\2)))
  }
  return $regsubex($iif($2,%x,$1),/(^\d+?(?=(?:\d{3})+(?:\.|$))|\G\d{3}(?=\d))/g,\t $+ $chr(44)) $+ $2
}



$hi!(3409734037340734,K) = 3,409,734,037,341K

$hi!(number) just adds commas, $hi!(number,bla) will divide like you asked.. bla can be T for 10^12, G for 10^9, M for 10^6 and K for 10^3. you can even add to them quite simply


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Mar 2005
Posts: 420
X
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
You can also try using the $Comma by FiberOptics .


If you have a plastic floor runner over your tiles, then you're one Hella Pinoy!
Joined: Aug 2004
Posts: 5
V
Nutrimatic drinks dispenser
Offline
Nutrimatic drinks dispenser
V
Joined: Aug 2004
Posts: 5
i found the longer way to be the most effective way in dealing with k and m in a math script.

on *:TEXT:!math *:#:{
if (m isin $2-) { set %math $replace($2-,m,000000) }
if (k isin $2-) { set %math $replace($2-,k,000) }
set %math $calc(%math)
msg $chan %math
}

you could also do something like this, $bytes(%math,bd) if you wanted to show both commas and decimals :P


Link Copied to Clipboard