Speed up development with full-stack environments for every branch.

Learn More

Divide two arbitrary precision numbers with bcdiv() function [bcmath and php-bcmath]

150 Runs 362 Views 30 Copies
Saved

Saved

gtsolutions 373

gtsolutions
published 4 years ago

<?php

/*
 * BC Math
 * divide two arbitrary precision numbers with bcdiv() function
 */
//dividing different sets of numbers
//if the third param will not be set there will be no decimals after the floating point of the result
$result_1 = bcdiv('123.654', '24');
$result_2 = bcdiv('2890.87', '180');
$result_3 = bcdiv('123.6658', '123', 3);

echo '<center>';
echo '<br /><div style="background-color:yellow;color:#000;padding:10px;width:500px;font-size:16px">
bcdiv(left_operand,right_operand,scale) Returns the result of the division as a string,
or NULL if right_operand is 0.
</div><br />';
echo '<br /><div style="background-color:green;color:#fff;padding:10px;width:500px;font-size:16px">
bcdiv("123.654","24") will output ' . $result_1 . '
</div><br />';
echo '<br /><div style="background-color:green;color:#fff;padding:10px;width:500px;font-size:16px">
bcdiv("2890.87","180") will output ' . $result_2 . '
</div><br />';
echo '<br /><div style="background-color:green;color:#fff;padding:10px;width:500px;font-size:16px">
bcdiv("123.6658","123",3) will output ' . $result_3 . '
</div><br />';
echo '</center>';
?>
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).