What is bcsub in PHP?
Overview
bcsub is a function in PHP that subtracts the second argument from the first argument.
Both arguments are arbitrary-precision numbers.
Syntax
bcsub(string $num1, string $num2, int $scale = null): string
Parameters
-
num1: variable of typestring. -
num2: variable of typestring. -
scale: variable of typeint. This is an optional parameter.scaleis used to set the number of digits after the decimal place in the result. The default value ofscaleis 0.
Return value
The bcsub function returns num2 - num1.
The function returned is of type
string.
Code
<?php$num1 = '1.34';$num2 = '4';echo bcsub($num1, $num2);echo bcsub($num1, $num2, 2);?>
Output
3
3.34