What is bcadd in PHP?
bcadd is a function in PHP that adds two arbitrary precision numbers.
Syntax
bcadd(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 bcadd function returns the sum of num1 and num2. The value returned is of type string.
Code
<?php$num1 = '1.34';$num2 = '4';echo bcadd($num1, $num2);echo bcadd($num1, $num2, 2);?>
Output
5
5.34