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



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

bcscale

Set default scale parameter for all bc math functions (PHP 4, PHP 5)
bool bcscale ( int scale )

Example 342. bcscale() example

<?php

// default scale : 3
bcscale(3);
echo
bcdiv('105', '6.55957'); // 16.007

// this is the same without bcscale()
echo bcdiv('105', '6.55957', 3); // 16.007

?>

Code Examples / Notes » bcscale

invincible

If you don't set the default scale, be careful when you're chaining together several BC math functions - since by default, these functions will round off your values, losing accuracy very quickly:
<?php
$a = 1.234
$b = 2.345
$c = 7.890
$ab = bcmul($a,$b);           // 2
$abc = bcmul($ab,$c);
echo $abc;                 // 15
?>
... compare with the answer you get when you use more decimal places:
<?php
$a = 1.234
$b = 2.345
$c = 7.890
bcscale(15);
$ab = bcmul($a,$b);           // 2.893730
$abc = bcmul($ab,$c);
echo $abc;                 // 22.83152970
?>


Change Language


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