rendered paste bodyalias calculate {
if ( $left($1,2) == -r ) { set -u0 %equa $right($1-,$calc($len($1-)-3)) | set -u0 %r $mid($1,3,1) }
if ( $left($1,2) != -r ) { set -u0 %equa $1- | set -u0 %r 7 }
set -u0 %ans $calc($replace(%equa,b,*1000000000,m,*1000000,k,*1000))
if ( %r isnum 0-7 ) { set -u0 %ans $round(%ans,%r) }
if ( %r == u ) { set -u0 %ans $ceil(%ans) }
if ( %r == d ) { set -u0 %ans $int(%ans) }
set -u0 %int $int(%ans)
set -u0 %dec $calc(%ans - %int)
set -u0 %i 1
set -u0 %j $int($calc(($len(%int)-1)/3))
:calc
if ( %j >= 1 ) { set -u0 %int $left(%int,$calc($len(%int) - %i * 4 + 1)) $+ $chr(44) $+ $right(%int,$calc(%i * 4 - 1)) }
inc %i
if ( %i <= %j ) { goto calc }
set -u0 %ans %int $+ $right(%dec,$calc($len(%dec) - 1 ))
if ( %r == 0 || %r isnum 2-6 ) { return %equa = %ans }
if ( %r == 1 ) { return %equa = %ans }
if ( %r == 7 ) { return %equa = %ans }
if ( %r == d ) { return %equa = %ans $chr(40) Rounded down $chr(41) }
if ( %r == u ) { return %equa = %ans $chr(40) Rounded up $chr(41) }
}
on *:TEXT:!calc *: { notice $nick $calculate($$2-) }