private function round($n, $sigfigs)
    {
        $new_log = (int)floor(log(abs($n), 10)); // Number of digits left of decimal - 1
        $rp = $sigfigs - $new_log - 1; // Number of decimal places needed
        $neg = $n < 0 ? '-' : ''; // Negative sign
        if ($this->bcmath) {
            if ($rp >= 0) {
                $n = bcadd($n, $neg . '0.' . str_repeat('0', $rp) . '5', $rp + 1);
                $n = bcdiv($n, '1', $rp);
            } else {
                // This algorithm partially depends on the standardized
                // form of numbers that comes out of bcmath.
                $n = bcadd($n, $neg . '5' . str_repeat('0', $new_log - $sigfigs), 0);
                $n = substr($n, 0, $sigfigs + strlen($neg)) . str_repeat('0', $new_log - $sigfigs + 1);
            }
            return $n;
        } else {
            return $this->scale(round($n, $sigfigs - $new_log - 1), $rp + 1);
        }
    }
private function round($n, $sigfigs)
    {
        $new_log = (int)floor(log(abs($n), 10)); // Number of digits left of decimal - 1
        $rp = $sigfigs - $new_log - 1; // Number of decimal places needed
        $neg = $n < 0 ? '-' : ''; // Negative sign
        if ($this->bcmath) {
            if ($rp >= 0) {
                $n = bcadd($n, $neg . '0.' . str_repeat('0', $rp) . '5', $rp + 1);
                $n = bcdiv($n, '1', $rp);
            } else {
                // This algorithm partially depends on the standardized
                // form of numbers that comes out of bcmath.
                $n = bcadd($n, $neg . '5' . str_repeat('0', $new_log - $sigfigs), 0);
                $n = substr($n, 0, $sigfigs + strlen($neg)) . str_repeat('0', $new_log - $sigfigs + 1);
            }
            return $n;
        } else {
            return $this->scale(round($n, $sigfigs - $new_log - 1), $rp + 1);
        }
    }
private function round ( $ n , $ sigfigs ) { $ new_log = ( int ) floor ( log ( abs ( $ n ) , 10 ) ) ; // Number of digits left of decimal - 1
 $ rp = $ sigfigs - $ new_log - 1 ; // Number of decimal places needed
 $ neg = $ n < 0 ? '-' : '' ; // Negative sign
 if ( $ this -> bcmath ) { if ( $ rp >= 0 ) { $ n = bcadd ( $ n , $ neg . '0.' . str_repeat ( '0' , $ rp ) . '5' , $ rp + 1 ) ; $ n = bcdiv ( $ n , '1' , $ rp ) ; } else { // This algorithm partially depends on the standardized
 // form of numbers that comes out of bcmath.
 $ n = bcadd ( $ n , $ neg . '5' . str_repeat ( '0' , $ new_log - $ sigfigs ) , 0 ) ; $ n = substr ( $ n , 0 , $ sigfigs + strlen ( $ neg ) ) . str_repeat ( '0' , $ new_log - $ sigfigs + 1 ) ; } return $ n ; } else { return $ this -> scale ( round ( $ n , $ sigfigs - $ new_log - 1 ) , $ rp + 1 ) ; } }
Rounds a number according to the number of sigfigs it should have,
using arbitrary precision when available.
@param float $n
@param int $sigfigs
@return string
Rounds a number according to the number of sigfigs it should have using arbitrary precision when available .