priMELval

calc 1.1 macro

Aug 31st, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. $${
  2. // Calc v1.1
  3. STRIP(&chat,%CHAT%)
  4. IFMATCHES(%&chat%,^/calc)
  5. FILTER
  6. IFMATCHES(%&chat%,^/calc ([0-9]+))
  7. MATCH(%&chat%,^/calc (.*)$,{&calc})
  8. REPLACE(&calc," ","")
  9. MATCH(%&calc%,([0-9]+)(.)([0-9]+),{#num1,&operator,#num2})
  10.  
  11. IF(%&operator%=="/")
  12. #num1a = #num1 * 1000
  13. #answer = #num1a / #num2
  14. IF(%#answer%<=99)
  15. SET(&answer,00%#answer%)
  16. ELSE
  17. SET(&answer,%#answer%)
  18. ENDIF
  19. MATCH(%&answer%,"([0-9]*)([0-9]{2})([0-9])",{#whole,&dec,#round})
  20. SET(#dec,%&dec%)
  21.  
  22. IF(%#round%>=5)
  23. SET(#dec,%&dec%)
  24. INC(#dec)
  25. ELSE
  26. SET(#dec,%&dec%)
  27. ENDIF
  28. IF(%#dec%==0)
  29. SET(&answer,%#whole%)
  30. ELSE
  31. IF(%#dec%<10)
  32. SET(&answer,"%#whole%.0%#dec%")
  33. ELSE
  34. SET(&answer,"%#whole%.%#dec%")
  35. ENDIF
  36. ENDIF
  37.  
  38. ELSEIF(%&operator%=="*")
  39. #answer = #num1 * #num2
  40. SET(&answer,%#answer%)
  41.  
  42. ELSEIF(%&operator%=="+")
  43. #answer = #num1 + #num2
  44. SET(&answer,%#answer%)
  45.  
  46. ELSEIF(%&operator%=="-")
  47. #answer = #num1 - #num2
  48. SET(&answer,%#answer%)
  49.  
  50. ENDIF
  51. LOG(&6[&4CALC&6] &a%#num1% %&operator% %#num2% = %&answer%)
  52. ELSE
  53. LOG(&6[&4CALC&6] &aBasic Calculator that doesn't work well)
  54. LOG(&6[&4CALC&6] &aUsage: <number> <*/+-> <number>)
  55. LOG(&6[&4CALC&6] &aPlease do not use decimals or negative numbers because &athe calculator is dumb)
  56. LOG(&6[&4CALC&6] &av 1.1)
  57. ENDIF
  58. ENDIF
  59. SET(
  60. }$$
Advertisement
Add Comment
Please, Sign In to add comment