This article is an example of the precise PHP computing function. Share to everyone for your reference, specific as follows:
Introduction: Be sure to ensure the accuracy of the data. This is the basic quality of a good programmer.
<?php/** * Exact addition * @param [type] $a [description] * @param [Type] $b [description]
* * Function Math_add ($a, $b, $scale = ' 2 ') {return bcadd ($a, $b, $scale);}/** * Precise subtraction * @param [type] $a [description]
* @param [Type] $b [description]/function math_sub ($a, $b, $scale = ' 2 ') {return bcsub ($a, $b, $scale);}/** * Precision multiplication * @param [Type] $a [description] * @param [Type] $b [description]/function Math_mul ($a, $b, $scale = ' 2 ') {return B
Cmul ($a, $b, $scale); /** * Exact Division * @param [type] $a [description] * @param [Type] $b [description]/function math_div ($a, $b, $scale = ' 2 '
{return Bcdiv ($a, $b, $scale);}/** * exact remainder/modulo * @param [type] $a [description] * @param [Type] $b [description] * * function Math_mod ($a, $b) {return bcmod ($a, $b);}/** * Compare size * @param [type] $a [description] * @param [type] $b [de Scription] * Greater than return 1 equals return 0 less than return-1 */function Math_comp ($a, $b, $scale = ' 5 ') {returns Bccomp ($a, $b, $scale);//Compare to decimal point Number of digits}
echo math_add (' 3.445 ', ' 3.444 '). " \ n "; Add 6.88 echo math_sub (' 3.445 ', ' 3.444 '). " \ n "; Minus 0.00 Echo Math_mul (' 3.445 ', ' 3.444 '). " \ n "; Multiply 11.86 echo math_div (' 3.445 ', ' 3.444 '). " \ n "; Except 1.00 echo math_mod (' 3.445 ', ' 3.444 '). \ n "; Modulo 0 echo math_comp (' 3.445 ', ' 3.444 '). " \ n ";//Compare 1 echo math_add (' 3.445 ', ' 3.444 ', ' 3 ')." \ n "; Add 6.889 echo math_sub (' 3.445 ', ' 3.444 ', ' 3 '). " \ n "; Minus 0.001 echo math_mul (' 3.445 ', ' 3.444 ', ' 3 '). " \ n "; Multiply 11.864 echo math_div (' 3.445 ', ' 3.444 ', ' 3 '). \ n "; Except 1.000 echo math_mod (' 3.445 ', ' 3.444 '). \ n "; Modulo 0 echo math_comp (' 3.445 ', ' 3.444 '). " \ n ';//compare 1?>
More interested in PHP related content readers can view the site topics: "PHP Mathematical Arithmetic Skills summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary", "PHP Array" Operation Techniques Encyclopedia, " PHP commonly used traversal algorithm and skills summary, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Regular Expression Usage summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.