Pyh.conf’25: a new PHP conference for the Russian-speaking community

Voting

: zero plus eight?
(Example: nine)

The Note You're Voting On

mwgamera at gmail dot com
17 years ago
These functions DO NOT round off your values. No arbitrary precision libraries do it this way. It stops calculating after reaching scale of decimal places, which mean that your value is cut off after scale number of digits, not rounded. To do the rounding use something like this:
<?php
function bcround($number, $scale=0) {
$fix = "5";
for (
$i=0;$i<$scale;$i++) $fix="0$fix";
$number = bcadd($number, "0.$fix", $scale+1);
return
bcdiv($number, "1.0", $scale);
}
?>

<< Back to user notes page

To Top