Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : BCMath Arbitrary Precision Mathematics Functions : bcdiv

bcdiv

Divide two arbitrary precision numbers (PHP 4, PHP 5)
string bcdiv ( string left_operand, string right_operand [, int scale] )

Example 338. bcdiv() example

<?php

echo bcdiv('105', '6.55957', 3);  // 16.007

?>

Code Examples / Notes » bcdiv

cristiandotzuddas nospam gmaildotcom

Decimal to binary conversion, using BC Math.
Note: this function is VERY slow if the decimal number is too big!
<?
function bc_decbin($dec_str) {
if (strlen($dec_str)>0) {
$bin_str = '';
do {
if (((int)$dec_str[strlen($dec_str)-1] % 2) === 0)
$bin_str .= '0';
else
$bin_str .= '1';

$dec_str = bcdiv($dec_str, '2');
} while ($dec_str!='0');

return strrev($bin_str);
}
else
return null;
}
?>
-----
Cristian
www.CodeFlower.com


gautam

<?php
//converting in to required precision of decimal points
$result= bcdiv(89.99999999997,2.57865741235478,2);
echo "$result";  // 34.90 result with 2 decimal points
?>


Change Language


Follow Navioo On Twitter
bcadd
bccomp
bcdiv
bcmod
bcmul
bcpow
bcpowmod
bcscale
bcsqrt
bcsub
eXTReMe Tracker