bcsub


php128 apg

SUBTRACT one arbitrary precision number from another.





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 bcsub 
( 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 = bcsub($vl01a, $vl01b);

$bca01b1 = bcsub($vl01a, $vl01b, $sc01a);

$bca01b2 = bcsub($vl01a, $vl01b, $sc01b);

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

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

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

?> 

 RESULT   

bcsub( 2020.106, 0.237 ) = 2019
[ NO SCALE IS PROVIDED ]

bcsub( 2020.106, 0.237, 0 ) = 2019
[ SCALE = 0 ]

bcsub( 2020.106, 0.237, 10 ) = 2019.8690000000
[ SCALE = 10 ]


  2 EXERCISE   

<?php

$vl02a 
= 0.237;

$vl02b = 2020.106;

$sc02a = 0;

$sc02b = 10;

$bca02a = bcsub($vl02a, $vl02b);

$bca02b1 = bcsub($vl02a, $vl02b, $sc02a);

$bca02b2 = bcsub($vl02a, $vl02b, $sc02b);

echo 
'bcsub( ' . $vl02a . ', ' . $vl02b . ' ) = ' . $bca02a . 
                                   
'<br>[ NO SCALE IS PROVIDED ]<br><br>'; 

echo 
'bcsub( ' . $vl02a . ', ' . $vl02b  . ', ' . $sc02a . ' ) = ' . $bca02b1 . 
                                   
'<br>[ SCALE = ' . $sc02a . ' ]<br><br>';

echo 
'bcsub( ' . $vl02a . ', ' . $vl02b  . ', ' . $sc02b . ' ) = ' . $bca02b2 . 
                                  
'<br> [ SCALE = ' . $sc02b . ' ]<br><br>';

?>