|
bcscale
Set default scale parameter for all bc math functions
(PHP 4, PHP 5)
Example 342. bcscale() example<?php Code Examples / Notes » bcscaleinvincible
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 ?> |