Have a custom function that is useful?
Just send me a link to a file with the function, or PM me the working code, and I'll display it in
this post.
1.
Evaluate mathematical expression
Here is a useful function that will take a mathematical expression and return the answer for it. Valid operators include plus + minus - multiply * divide / modulus % carrot/power ^ and parentheses ().
When used in BB Code, have one argument and it should function like so:
[math]5*6%3+((45/5)/4)[/math]
5*6%3 = 0
(45/5)/4 = 2.25
= 2.25
Here is the function:
PHP Code:
function arithmetic($expression)
{
$expression = preg_replace('([^0-9\+\-*\/%\^\(\)])', '', trim($expression));
eval('$answer ='.$expression.';');
return $answer;
}
Careful with parentheses. If you have (5/5)5 it will result in an error, and nothing will be returned.