PHP precise computing function example, php example
This example describes the PHP precise computing function. We will share this with you for your reference. The details are as follows:
Introduction: ensure data accuracy. This is the basic literacy 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 );} /*** exact subtraction ** @ param [type] $ a [description] * @ param [type] $ B [description] */function math_sub ($ a, $ B, $ scale = '2') {return bcsub ($ a, $ B, $ scale );} /*** exact multiplication ** @ param [type] $ a [description] * @ param [type] $ B [description] */function math_mul ($ a, $ B, $ Scale = '2') {return bcmul ($ 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 ($, $ B) {return bcmod ($ a, $ B );} /*** compare size ** @ param [type] $ a [description] * @ param [type] $ B [description] * large If 1 is returned, return 0 is less than-1 */function math_comp ($ a, $ B, $ scale = '5') {return bccomp ($ a, $ B, $ scale); // compare to the decimal point} 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 by 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 by 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?>