Output is ignoring decimal part using bcdiv

Output is ignoring decimal part using bcdiv

Code:

<?php
$a = "38.5";
$result = bcdiv(bcadd($a, "6"), "2", 100);
echo $result;
?>

Showing output:

22.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Expected output:

22.2500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

Answer

<?php
$a = "38.5";
$result = bcdiv(bcadd($a, "6", 100), "2", 100);
echo $result;
?>


Solved!!. 

Enjoyed this question?

Check out more content on our blog or follow us on social media.

Browse more questions