PHP precise computing function example, php example

Source: Internet
Author: User
Tags php example

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?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.