Conscious commented on a Page, !calc Calculator  -  May 20, 2011

Okay, so this was in a high need of a recode.
First of all, with the method I used above it replaced 'm' with 1000000
That works in some cases, but if you have !calc 1m/1m it returns 1,000,000,000,000 instead of 1.
So I turned it into regex, making it do something like $calc((1
1000000)/(1*1000000))
However this wasn't capturing the . so I made another edit to incorporate that.

...then I made it one line xD

Old script for history to anyone who's interested, editing the new script above now.

alias -l comma {
  var %a, %b = $regsub($ticks,$1,/\G([+-]?\d+?)(?=(?:\d{3})++(?=\.\d++$|$))/g,\1 $+ $chr(44),%a)
  return %a
}

on *:text:!calc*:#: {
    if ($1 == !calc) {
      if ($2-) {
        if ($chr(37) isin $1-) {
          msg $chan You cannot use percent in this calculator, sorry.
        }
        else {
          if ($remove($2-,k,m,b,$chr(44),.,+,-,/,*,^) !isnum) msg $chan Sorry $nick $+ , I can't calculate words.
          else {
            var %calc1 $comma($calc($replace($2-,k,*1000,m,*1000000,b,*1000000000,$chr(44),$null)))
            timer 1 1 msg $chan 4Calculating: 03 $+ $2-
            timer 1 2 msg $chan 4Result: 03 $+ %calc1
            if (%calc1 == 0) {       
              timer 1 5 msg $chan If 0 is not the correct answer, that is because this calculator can't handle some or all of the characters used or the formula used.
            }
          }
          else msg $chan I can't calculate nothing...
        }
      }
    }
  }
 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.