mIRC Homepage
Posted By: blk calc script with k and m - 12/03/06 06:42 PM
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)
Posted By: DaveC Re: calc script with k and m - 12/03/06 07:25 PM
/help $bytes
Posted By: blk Re: calc script with k and m - 12/03/06 07:50 PM
ook, thats one big headache...
How about, how do I make commas in it?
Posted By: DaveC Re: calc script with k and m - 13/03/06 02:43 AM
assume %value holds the value

$bytes(%value,b)

** amazing **
Posted By: jaytea Re: calc script with k and m - 13/03/06 03:04 AM
$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
Posted By: xDaeMoN Re: calc script with k and m - 13/03/06 04:16 AM
You can also try using the $Comma by FiberOptics .
Posted By: Vulcan Re: calc script with k and m - 14/03/06 08:15 AM
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
© mIRC Discussion Forums