-
Notifications
You must be signed in to change notification settings - Fork 4
mathToFloat
Tonaie edited this page Feb 18, 2018
·
3 revisions
Deprecated due to faults in the algorithm. Use pandaMath
mathToFloat is a function that turns a string of math into a float. It is slow and memory-heavy so only use it if you absolutely have to. The math follows the standard mathematical order, IE. multiplication before addition. The function will not syntax check, so make sure you have it right.
mathToFloat(string al, integer part, string varObj)
- al = The algorithm to run. Like "3*4"
- part = Used internally to track parentheses recursion. Should always be 0 when initially calling the function.
- varObj = Optional JSON object with variables.
It is recommended that you use the libJasPre macro algo(string al, string varObjs) instead of calling the function directly.
algo("3*3", "") returns 9.0000000
algo("4*D", "{\"D\":1.5}") returns 6.0000
algo("-2*(1+1)", "") returns -4
algo("CEIL(0.1)+FLOOR(1.9)", "") returns 2
| Operator | Description |
|---|---|
| +- | Addition/Subtraction |
| */ | Multiplication/Division |
| ^ | Exponents |
| () | Parentheses |
| Function | Description |
|---|---|
| RAND(n) | Returns a random float between 0 and n |
| CEIL(n) | Rounds n up |
| FLOOR(n) | Rounds n down |
| ROUND(n) | Rounds n to the nearest whole |