Home  >  Article  >  Backend Development  >  Floating point data in PHP needs to be solved in different ways_PHP Tutorial

Floating point data in PHP needs to be solved in different ways_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 10:36:16946browse

Php: BCMath

bc is the abbreviation of Binary Calculator. The parameters of the bc* function are all 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 of bcscale is used. value. Here, large numbers are directly represented by a string consisting of 0-9, and the calculation result is also a string.

bcadd — Add two high-precision numbers
bccomp — Compare two high-precision numbers, returning -1, 0, 1
bcdiv — Divide two high-precision numbers
bcmod — Find the remainder of a high-precision number
bcmul — Multiply two high-precision numbers
bcpow — Find the power of a high-precision number
bcpowmod — Find the modulus of the power of a high-precision number, very commonly used in number theory
bcscale — Configure the default number of decimal points, which is equivalent to "scale=" in Linux bc
bcsqrt — Find the square root of a high-precision number
bcsub — Subtract two high-precision numbers

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

Copy code The code is as follows:

/*bcsub function description
This function combines two high-precision To subtract degrees of numbers, pass in two strings and subtract the value on the right (right operand) from the left (left operand) value. scale is an optional option that indicates the required number of digits after the decimal point of the return value. */
//The following code ensures one decimal digit
$aa=bcsub(134.7,52.5,1);
echo $aa;//exit;
$bb= bcsub($aa,82.2,1);
echo $bb;//exit;
//floor

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/740220.htmlTechArticlePhp: BCMath bc is the abbreviation of Binary Calculator. The parameters of the bc* function are all operands plus an optional [int scale], such as string bcadd(string $left_operand, string $right_operand[,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn