$money

By Kirby on Jan 15, 2009

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) }
  }
}

Comments

Sign in to comment.
Patatje-oorlog   -  Jan 17, 2009

Very Nice Script

Keep up the work

 Respond  
Linuxuser   -  Jan 17, 2009

very nice script good to see people contribute i like it

 Respond  
TheImrac   -  Jan 16, 2009
alias money { return $regsubex($1,/^(\d+)(\.\d+)?$/,$bytes(\1,b)\2) }

or

alias money { if ($regex($1,/^(\d+)(\.\d+)?$/)) return $bytes($regml(1),b) $+ $regml(2) }
 Respond  
Blitzjager   -  Jan 16, 2009

When you gettok you could use like $iif($left($gettok(blah),3) isnum 995-999,00,$round(blah)) and then do +1 if it's 00

 Respond  
NIGathan   -  Jan 16, 2009

I tried already, and it still returned the 0's

Actually, thats what my original script does.. :/

 Respond  
Jonesy44   -  Jan 16, 2009

Wouldnt it be better to rouond it then split it?

 Respond  
NIGathan   -  Jan 16, 2009

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.

 Respond  
Jonesy44   -  Jan 16, 2009

Yep.. :) lol!!

 Respond  
Blitzjager   -  Jan 16, 2009

xD
I'm just mad that it only takes one thing to do what we did lol.

 Respond  
Jonesy44   -  Jan 16, 2009

It just can't take on that much.. not that it'd ever be necesary.. who uses money terms over a trillion?

 Respond  
Kirby   -  Jan 16, 2009

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?

 Respond  
Blitzjager   -  Jan 16, 2009

Me and Kirby decided we won.
$bytes stops after a bit, I hate regex, and Nigathan's returned some 000'000 even though it wasn't in what we used. =D

/me strokes his epenis.

 Respond  
Jonesy44   -  Jan 16, 2009

ok, NIGathan, then use

alias money { return $+($,$bytes($gettok($1,1,46),b),$iif($gettok($1,2,46),.),$round($gettok($1,2,46),2)) }
 Respond  
Blitzjager   -  Jan 16, 2009

alias money { return $+($,$bytes($round($1,2),bd)) }

/me feels better now

I haven't tried Brando's but with what I just posted and with jonesy's
//echo -a $money(2394283904320923483.2343234934)
returned $23,343,432,238,948,932

Brando's works but doesn't round(probably easy enough to add)

 Respond  
NIGathan   -  Jan 16, 2009

jonesy, It isnt meant to but it does:

$bytes(9876543.212,b) returns 9,876,543

 Respond  
Kirby   -  Jan 16, 2009

Error fixed, I used the wrong variable...-__-
Didn't know that $bytes would work, lol.

 Respond  
Jonesy44   -  Jan 16, 2009

NIGathan.. it's not supposed to round.. that's what $round is for .. o.o

 Respond  
NIGathan   -  Jan 16, 2009

$bytes fails for this, jonesy, it sucks with rounding.

lol @ blitzjager

 Respond  
Blitzjager   -  Jan 16, 2009

Rofl. Well now I feel smart.

Guess me and Kirby get 4th place for this. :(

Edit: Not mad at myself enough yet.

DAMMIT! >:[

 Respond  
Jonesy44   -  Jan 16, 2009
alias money { return $+($,$bytes($1,b)) }

or am i missing something?

 Respond  
BrAndo   -  Jan 16, 2009
alias money return $+($,$regsubex($token($1,1,46),/\B(?=(\d{3})+$)/g,`),.,$token($1,2,46))
 Respond  
NIGathan   -  Jan 16, 2009

It should have it I believe :/

Type /help $+

And if multiple topics are found, then it supports it, if not, it doesnt.

 Respond  
Blitzjager   -  Jan 16, 2009

Possibly. 6.31?

 Respond  
NIGathan   -  Jan 16, 2009

Are you using a version that doesnt support ()'s in $+? Because it indeed works, but if thats the case, just change the commas to $+ so it looks like: if ($calc(%x % 3) == 0) { var %return $right($1,3) $+ $chr(39) $+ %return | tokenize 32 $left($1,-3) }

Do the same with the other $+() aswell

 Respond  
Blitzjager   -  Jan 16, 2009

Forgot to change a variable. :(

And I don't see why but * Invalid format: $+ (line 5, script19)
And I was looking at /tokenize but I wasn't quite sure how to use it

 Respond  
NIGathan   -  Jan 16, 2009

It was broken :P

Scakk just showed it, so I went and fixed it :D

Also using % 3 in $calc is much more efficient

 Respond  
Blitzjager   -  Jan 16, 2009

If it's not broken don't fix it? >:(

 Respond  
NIGathan   -  Jan 16, 2009
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)
}
 Respond  
Blitzjager   -  Jan 16, 2009

Replace the var in the while with

var %result $instok(%result,$mid(%dollars,$calc( [ %stuff ] * [ %length ] ),3),$calc($numtok(%result,44)+1),39) | dec %length
 Respond  
Scakk   -  Jan 16, 2009

This --> //echo -ag $money(9876543)
Returned --> $9'987'987

Issue it would appear has been found.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.