BC Math Binary Calculator
suggest changeIntroduction
BCMath calculates with numbers of any size, passed as strings. The scale argument is the number of digits after the decimal point. It is exact decimal arithmetic, unlike PHP's binary floats.
Syntax
- string bcadd ( string $left_operand , string $right_operand [, int $scale = 0 ] )
- int bccomp ( string $left_operand , string $right_operand [, int $scale = 0 ] )
- string bcdiv ( string $left_operand , string $right_operand [, int $scale = 0 ] )
- string bcmod ( string $left_operand , string $modulus )
- string bcmul ( string $left_operand , string $right_operand [, int $scale = 0 ] )
- string bcpowmod ( string $left_operand , string $right_operand , string $modulus [, int $scale = 0 ] )
- int bcscale ( int $scale = 0 ) — returns the previous scale since PHP 8; returned
truebefore PHP 8 - string bcsqrt ( string $operand [, int $scale = 0 ] )
- string bcsub ( string $left_operand , string $right_operand [, int $scale = 0 ] )
Parameters
bcadd | Add two arbitrary precision numbers. |
— | — |left_operand | The left operand, as a string. |right_operand | The right operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |bccomp | Compare two arbitrary precision numbers. |left_operand | The left operand, as a string. |right_operand | The right operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place which will be used in the comparison.|bcdiv | Divide two arbitrary precision numbers. |left_operand | The left operand, as a string. |right_operand | The right operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |bcmod | Get modulus of an arbitrary precision number. |left_operand | The left operand, as a string. |modulus | The modulus, as a string. |bcmul | Multiply two arbitrary precision numbers. |left_operand | The left operand, as a string. |right_operand | The right operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |bcpow | Raise an arbitrary precision number to another. |left_operand | The left operand, as a string. |right_operand | The right operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |bcpowmod | Raise an arbitrary precision number to another, reduced by a specified modulus. |left_operand | The left operand, as a string. |right_operand | The right operand, as a string. |modulus | The modulus, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |bcscale | Set default scale parameter for all bc math functions. |scale | The scale factor. |bcsqrt | Get the square root of an arbitrary precision number. |operand | The operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |bcsub | Subtract one arbitrary precision number from another. |left_operand | The left operand, as a string.|right_operand |The right operand, as a string. |scale | An optional parameter to set the number of digits after the decimal place in the result. |
Remarks
If you omit scale, BCMath uses the current scale. That scale starts at 0, so results are integral until bcscale() changes it. bcmod() does not take a scale.