Floating point data in PHP requires a different approach

  • 2021-01-22 04:55:02
  • OfStack

Php: BCMath

bc is short for Binary Calculator. The bc* function takes 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 1 string consisting of 0 to 9, and the calculation result returns 1 string.

bcadd -- Add two high-precision numbers
bccomp -- Compare two high-precision numbers and return -1, 0, 1
bcdiv -- Divide two high-precision numbers
bcmod -- Finding the remainder of high-precision numbers
ES34en - Multiply two high-precision numbers
bcpow -- High precision digital power
bcpowmod -- for high-precision digital power for modulus, 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 high-precision numbers
bcsub -- Subtract two high-precision numbers

Refer to the manual for applications of these functions.


/*bcsub  Function description 
 This function will be 2 Subtract a number of high precision, pass in 2 The string to the left  (left operand)  Subtract the right-hand side  (right operand)  Value. scale  is 1 A dispensable options, said the return value of � the decimal places. */
// The code below I'm guaranteeing the decimal point 1 A digital 
$aa=bcsub(134.7,52.5,1);
echo $aa;//exit;
$bb=bcsub($aa,82.2,1);
echo $bb;//exit;
// Floor of a building 


Related articles: