I see many casino games on my network and some gamebots on Hawkee, regarding money.
I often tend to see numbers such as $1000000 where there are no commas or apostrophes to separate quantities, making them harder to see.
With $money, you can convert numbers such as $1000000 to $1'000'000.
You can also round numbers with decimals, for example, $3294.786 to $3'294.79.
Blitzjager contributed A LOT to this and mostly coded this. (Idea was mine though).
Usage
$money(N)
where the letter represents:
N - number to convert
Example
$money(1000000)
Returns $1'000'000
Enjoy! :D
alias money {
if ($1 isnum) {
if ($chr(46) isin $1) { var %dollars $gettok($1,1,46) | var %cents $remove($round($+($chr(46),$gettok($1,2,46)),2),0.) }
else { var %dollars $1 }
var %length $ceil($calc($len(%dollars)/3))
if (%length > 1) {
dec %length
var %result $addtok(%result,$left(%dollars,$calc($len(%dollars)-$calc( [ %length ] * 3))),39) | var %stuff -3
while (%length) {
var %result $instok(%result,$mid(%dollars,$calc( [ %stuff ] * [ %length ] ),3),$calc($numtok(%result,39)+1),39) | dec %length
}
}
else { var %result %dollars }
if ($chr(46) isin $1) { return $+($chr(36),%result,$chr(46),%cents) }
else { return $+($chr(36),%result) }
}
}
That is a bug in both $round and $calc D:
Also heres a bug in yours:
//echo -ag $money(234803298432432432432343324032.9999999999999999999999999999)
returns: $234'803'298'432'432'432'432'343'324'032.1
When it should return a solid $234'803'298'432'432'432'432'343'324'033
This is why you should $round it all together first, but then you get the 0's because the numbers too large.
I found a bug with your original code NIGathan.
I tried using yours but with an obscenely large number
//echo -a $money2(234803298432432432432343324032.33432234234323443223480329803298432)
returned: $234'803'298'432'432'420'000'000'000'000
But ours:
//echo -a $money(234803298432432432432343324032.33432234234323443223480329803298432)
returned: $234'803'298'432'432'432'432'343'324'032.33
Is that supposed to happen?
alias money {
tokenize 46 $round($1,2)
var %x 1, %y $len($1), %z $2
while (%x <= %y) {
if ($calc(%x % 3) == 0) { var %return $+($right($1,3),$chr(39),%return) | tokenize 32 $left($1,-3) }
inc %x
}
if ($1) var %return $+($1,$chr(39),%return)
return $chr(36) $+ $iif($right(%return,-1) == $chr(39),$left(%return,1),$left(%return,-1)) $+ $iif(%z,. $+ $v1)
}