In PHP development, there is a fractional subtraction scenario. The result is that it is not equal to the expected value,
On the internet also found some information, found that the problem of precision. Finally, the Bccomp function was used to solve the problem.
Bccomp
Compare two high-precision numbers.
Syntax: int Bccomp (string left operand, string right operand, int. [scale]);
return value: integer
Types of functions: mathematical operations
This function compares two high-precision numbers. Enter two strings, and return 0 if the two string is the same size, and return +1 if the left operand is larger than the right operand, or 1 if the left number string is smaller than the right. Scale is an optional option that represents the number of digits required after the decimal point of the return value.
PHP decimal addition and subtraction accuracy problem