PHP Precise computing features sample _php tips

Source: Internet
Author: User

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.

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.