PHP module Bcmath for Precision Computing

Source: Internet
Author: User
Tags square root

Php:bcmath

BC is the abbreviation for binary calculator. The arguments to the bc* function are the operands plus an optional [int scale], such as String Bcadd (String $left _operand, String $right _operand[, int $scale]), if scale is not provided , the default value of Bcscale is used. Here the large number is directly represented by a string of 0-9, and the result of the calculation is also a string.


Bcadd-adds two high-precision numbers
Bccomp-compares two high-precision numbers, returns-1, 0, 1
bcdiv-divides two high-precision numbers
Bcmod-seeking high precision digital remainder
bcmul-multiply two high-precision numbers
bcpow-High Precision Digital exponentiation
Bcpowmod-to find high-precision digital exponentiation, number theory is very common
bcscale-Configure the default number of decimal places, equivalent to the "scale=" in the Linux BC
bcsqrt-to find the square root of high precision number
bcsub-to subtract two high-precision numbers

You can refer to the manual to check the application of these functions.

Installation of Bcmath
Bcmath this extension in the PHP compression package is all, need to recompile to be able to support;
CD Php-5.2.7/ext/bcmath
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
Make && do install (makes can get the so path)
So path copy to extension path
Vim php.ini
Extension=bcmath.so
Restart Apach


PHP code?

/*bcsub function Description
This function subtracts two high-precision numbers, passing in two strings, subtracting the right operand value from the left operand. Scale is an optional option that represents the number of digits required after the decimal point of the return value. */
The following code I was guaranteed a decimal digit
$aa =bcsub (134.7,52.5,1);
echo $aa;//exit;
$BB =bcsub ($aa, 82.2, 1);
echo $bb;//exit;

PHP module Bcmath for Precision Computing

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.