A wage calculation formula is usually defined in the wage system. For example, real-time = should be issued-should be deducted and so on. To calculate such an expression, the traditional method is to use a reverse polish expression to parse it.
The following describes a simple method for computing.
Use RPN. php In the pear library of PHP. Usage:
<?
Include 'include/pear/RPN. php ';
// $ Expression = "(2 ^ 3) + sin (30 )-(! 4) + (3/4 )";
$ Expression = "(2.33*6 )";
$ RPN = new math_rpn ();
Echo $ RPN-> calculate ($ expression, 'deg ', false );
?>
That is to say, replace each item in the formula with a specific value, and then calculate the value.
The operators supported by RPN are:
VaR $ _ operation = array (
'(' => Array ('left bracket ', 0 ),
')' => Array ('Right bracket ', 1 ),
'+' => Array ('sum', 1, 2, '_ Sum '),
'-' => Array ('difference ', 1, 2,' _ Difference '),
'*' => Array ('multiplication ', 2, 2,' _ multiplication '),
'/' => Array ('division ', 2, 2,' _ division '),
'R' => array ('root', 3, 2, '_ root '),
'^' => Array ('power', 3, 2, '_ power '),
'Sin' => array ('sine', 3, 1, '_ sin '),
'Cos '=> array ('cosine', 3, 1,' _ cos '),
'Tan' => array ('tangent', 3, 1, '_ tan '),
'Asin' => array ('asine', 3, 1, '_ asin '),
'Accos '=> array ('acosine', 3, 1,' _ accos '),
'Https' => array ('hangout', 3, 1, '_ https '),
'Sqrt '=> array ('square root', 3, 1,' _ SQRT '),
'Expires' => array ('Power of E', 3, 1, '_ expires '),
'Log' => array ('logarithm ', 3, 1,' _ log '),
'Ln '=> array ('natural logarithm', 3, 1, '_ ln '),
'E' => array ('Power of 10', 3, 1, '_ e '),
'Abs '=> array ('absolute value', 3, 1,' _ ABS '),
'! '=> Array ('factorial', 3, 1, '_ factorial '),
'Pi '=> array ('value of PI', 4, 0, '_ const_pi '),
'E' => array ('value of E', 4, 0, '_ const_e '),
'Mod' => array ('modulo', 3, 2, '_ mod '),
'Div '=> array ('integer division', 3, 2, '_ Div '),
);
Of course, we can add our own functions, such as tax () for tax calculation.