Php BC high-precision function library and bc precision function library

Source: Internet
Author: User

Php BC high-precision function library and bc precision function library


<? Php *************************************** **************************************** * ******* php BC high-precision function library * php bc math contains: add, compare, divide, subtract, remainder, multiply, n, configure the default number of decimal places, square * these functions are useful when it comes to money-related computing ************************** **************************************** **************************************** **************************************** * ***************************** comparison of two high-precision numbers * situation, 0.00! = 0 * int bccomp (string $ left_operand, string $ right_operand [, int $ scale]) * $ left = $ right returns 0 * $ left <$ right returns-1 * $ left> $ right returns 1 * $ scale decimal place ********** **************************************** ************************************ $ a = 4.45; $ B = 5.54; if (bccomp ($ a, $ B, 2) = 0) {}************************************** **************************************** * ******** add two high-precision numbers * string bcadd (String $ left_operand, string $ right_operand [, int $ scale]) * $ scale returns the number of decimal places ********************************** **************************************** * ************ $ a = 1.0321456; $ B = 0.0123456; $ c = bcadd ($ a, $ B, 2); // var_dump ($ c ); **************************************** **************************************** * ****** subtraction of two high-precision numbers * sstring bcsub (string $ left_operand, string $ right_operand [, Int $ scale]) * $ scale returns the number of decimal places ********************************** **************************************** * ************ $ a = 1.0321456; $ B = 3.0123456; $ c = bcsub ($ a, $ B, 2); var_dump ($ c ); **************************************** * **************** remainder/modulo of two high-precision computations * string bcmod (string $ left_operand, string $ modulus) **************************************** * ************** $ a = 6; $ B = 4; $ c = bcmod ($ a, $ B); // Var_dump ($ c ); **************************************** **************************************** * ****** division of two high-precision numbers * string bcdiv (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale indicates the number of decimal places. The default value is 0 ******************************** **************************************** * ************** $ a = 6; $ B = 5; $ c = bcdiv ($ a, $ B, 3); // var_dump ($ c ); **************************************** ***** **************************************** * ** Multiply two high-precision numbers * string bcmul (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale indicates the number of decimal places. The default value is 0 ******************************** **************************************** * ************** $ a = 3.1415926; $ B = 2.4569874566; $ c = bcmul ($ a, $ B, 6); // var_dump ($ c ); **************************************** **************************************** * ******* two highs The power of the number of precision * string bcpow (string $ left_operand, string $ right_operand [, int $ scale]) * $ scale indicates the number of decimal places. The default value is 0 ******************************** **************************************** * ************** $ a = 3.1415926; $ B = 2; $ c = bcpow ($ a, $ B, 3); // var_dump ($ c ); **************************************** * ********* calculate the square root of a precise number * string bcsqrt (string $ operand [, int $ scale]) * $ scale the number of decimal places is 0 by default ***************** * ********************************* $ B = bcsqrt ($ a, 6); // var_dump ($ B ); * ***************************** set the decimal point of the bc function * bool bcscale (int $ scale) * $ scale the number of decimal places is 0 ******************************// bcscale () ;?>


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.