bcadd


php128 apg

ADD two arbitrary precision numbers.





This function returns the ( $num1 + $num2 ) as STRING.

If $scale is omited, this function will default to the scale set globally with the bcscale function, or fallback to 0 if this has not been set.



<?php

string bcadd 
string $num1
                       
string $num2
                          ?
int $scale null )


where,

$num1 The left operand as STRING

$num2 
The right operand as STRING

$scale 
The number of decimal places 
                                      considered by this operation

?>
 

$num1


The left operand treated as STRING.



$num2


The right operand treated as STRING.



$scale


The number of decimal places to be considered.

This is nullable as of PHP 8.0.XX.



  1 EXERCISE   

<?php

$vl01a 
2020.106;

$vl01b '0.237';

$sc01a 0;

$sc01b 10;

$bca01a bcadd($vl01a$vl01b);

$bca01b1 bcadd($vl01a$vl01b$sc01a);

$bca01b2 bcadd($vl01a$vl01b$sc01b);

echo 
'bcadd( ' $vl01a ', ' $vl01b ' ) = ' $bca01a 
                          
'<br>[ NO SCALE IS PROVIDED ]<br><br>'

echo 
'bcadd( ' $vl01a ', ' $vl01b  ', ' $sc01a ' ) = ' $bca01b1 
                          
'<br>[ SCALE = ' $sc01a ' ]<br><br>';

echo 
'bcadd( ' $vl01a ', ' $vl01b  ', ' $sc01b ' ) = ' $bca01b2 
                          
'<br> [ SCALE = ' $sc01b ' ]<br><br>';

?> 

 RESULT   

bcadd( 2020.106, 0.237 ) = 2020.3430
[ NO SCALE IS PROVIDED ]

bcadd( 2020.106, 0.237, 0 ) = 2020
[ SCALE = 0 ]

bcadd( 2020.106, 0.237, 10 ) = 2020.3430000000
[ SCALE = 10 ]