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
970449
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);
        }
    }
176995
private function round($number)
    {
        if (null !== $this->scale && null !== $this->roundingMode) {
            // shift number to maintain the correct scale during rounding
            $roundingCoef = pow(10, $this->scale);
            // string representation to avoid rounding errors, similar to bcmul()
            $number = (string) ($number * $roundingCoef);

            switch ($this->roundingMode) {
                case self::ROUND_CEILING:
                    $number = ceil($number);
                    break;
                case self::ROUND_FLOOR:
                    $number = floor($number);
                    break;
                case self::ROUND_UP:
                    $number = $number > 0 ? ceil($number) : floor($number);
                    break;
                case self::ROUND_DOWN:
                    $number = $number > 0 ? floor($number) : ceil($number);
                    break;
                case self::ROUND_HALF_EVEN:
                    $number = round($number, 0, PHP_ROUND_HALF_EVEN);
                    break;
                case self::ROUND_HALF_UP:
                    $number = round($number, 0, PHP_ROUND_HALF_UP);
                    break;
                case self::ROUND_HALF_DOWN:
                    $number = round($number, 0, PHP_ROUND_HALF_DOWN);
                    break;
            }

            $number /= $roundingCoef;
        }

        return $number;
    }
259806
private function numberToNumerals($number, array $numerals)
    {
        $string = '';

        while ($number > 0) {
            foreach ($numerals as $n => $t) {
                if ($number >= $n) {
                    $string .= $t;
                    $number -= $n;
                    break;
                }
            }
        }

        return $string;
    }
397203
public function numberFormat($number, int $decimals = 0): string
    {
        if (!isset($this->numberFormatter)) {
            $this->numberFormatter = new NumberFormatter($this->intuition->getLang(), NumberFormatter::DECIMAL);
        }
        $this->numberFormatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
        return $this->numberFormatter->format($number);
    }
129229
private function make_counter($n, $type, $pad = null)
    {
        $n = intval($n);
        $text = "";
        $uppercase = false;

        switch ($type) {
            case "decimal-leading-zero":
            case "decimal":
            case "1":
                if ($pad) {
                    $text = str_pad($n, $pad, "0", STR_PAD_LEFT);
                } else {
                    $text = $n;
                }
                break;

            case "upper-alpha":
            case "upper-latin":
            case "A":
                $uppercase = true;
            case "lower-alpha":
            case "lower-latin":
            case "a":
                $text = chr(($n % 26) + ord('a') - 1);
                break;

            case "upper-roman":
            case "I":
                $uppercase = true;
            case "lower-roman":
            case "i":
                $text = Helpers::dec2roman($n);
                break;

            case "lower-greek":
                $text = Helpers::unichr($n + 944);
                break;
        }

        if ($uppercase) {
            $text = strtoupper($text);
        }

        return "$text.";
    }
590545
public static function round($num, int $precision=0, int $mode=\PHP_ROUND_HALF_UP) {
		ref\format::round($num, $precision, $mode);
		return $num;
	}
453051
def round_sig(x, n, scien_notation = False):
    if x < 0:
        x = x * -1
        symbol = '-'
    else:
        symbol = ''
    
    
    ''''''
    if type(n) is not types.IntType:
        raise TypeError, "n must be an integer"
    try:
        x = float(x)
    except:
        raise TypeError, "x must be a floating point object"
    form = "%0." + str(n-1) + "e"
    st = form % x
    num,expo = epat.findall(st)[0]
    expo = int(expo)
    fs = string.split(num,'.')
    if len(fs) < 2:
        fs = [fs[0],""]
    if expo == 0:
#         print 'One', num
        return symbol + num
    elif expo > 0:
        if len(fs[1]) < expo:
            fs[1] += "0"*(expo-len(fs[1]))
        st = fs[0]+fs[1][0:expo]
        if len(fs[1][expo:]) > 0:
            st += '.'+fs[1][expo:]
#         print 'Two', st
        return symbol + st
    else:
        expo = -expo
        if fs[0][0] == '-':
            fs[0] = fs[0][1:]
            sign = "-"
        else:
            sign = ""
            
        if scien_notation:
            coso = float(sign+"0."+"0"*(expo-1)+fs[0]+fs[1])
            scient_format = '{:.' + str(n) + 'e}'
            StrScientific = scient_format.format(coso)
#             print 'three', StrScientific
            return symbol + StrScientific
        
        else:
            formated = sign+"0."+"0"*(expo-1)+fs[0]+fs[1]
            if len(formated) > (n+5):
                formated = '0.' + '0' * n
#             print 'cuantro', formated
            return symbol + formated
600273
public function formatFilesize($size, $decimals = 0)
    {
        $sizes = array(" B", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
        if ($size == 0) {
            return ('n/a');
        } else {
            return (round($size / pow(1024, ($i = floor(log($size, 1024)))), $decimals) . $sizes[$i]);
        }
    }
13415
public function getSigFigs($n)
    {
        $n = ltrim($n, '0+-');
        $dp = strpos($n, '.'); // decimal position
        if ($dp === false) {
            $sigfigs = strlen(rtrim($n, '0'));
        } else {
            $sigfigs = strlen(ltrim($n, '0.')); // eliminate extra decimal character
            if ($dp !== 0) {
                $sigfigs--;
            }
        }
        return $sigfigs;
    }
706607
public static function round($value, int $precision = null)
    {
        if (!is_numeric($value)) {
            throw new InvalidArgumentException("Value must be numeric");
        }

        return round($value, $precision ?? static::getRoundPrecision());
    }
1076396
private function base62toDec($n)
    {
        $n = preg_replace("/[^A-Za-z0-9 ]/", '', $n);
        $vals = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $vals = array_flip(str_split($vals));
        $out = 0;
        $len = strlen($n);
        for ($i = 0; $i < $len; $i++)
        {
            $c = $n[$len - ($i + 1)];
            $out += $vals[$c] * pow(62, $i);
        }

        return (int)$out;
    }
787207
private function sanitizeRoundsOfAiming($roundsOfAiming): int
    {
        try {
            $roundsOfAiming = ToInteger::toPositiveInteger($roundsOfAiming);
            if ($roundsOfAiming > 3) {
                return 3;
            }

            return $roundsOfAiming;
        } catch (\Granam\Integer\Tools\Exceptions\Exception $integerException) {
            throw new Exceptions\InvalidFormatOfRoundsOfAiming($integerException->getMessage());
        }
    }
89842
public static function invertBits($n){
		$bits = \floor(\log($n, 2)) + 1;
		$mask = (1 << $bits) - 1;
		return $n ^ $mask;
	}
836079
public static function round ($fValue, $iPrecision = 0)
    {
        $sPrintfPrecision = max(0, $iPrecision);
        return sprintf("%01.{$sPrintfPrecision}f", round($fValue, $iPrecision));
    }
741199
private function roundDigit(Number $number)
    {
        if ($number->isCloserToNext()) {
            return bcadd(
                (string) $number,
                $number->getIntegerRoundingMultiplier(),
                0
            );
        }

        return bcadd((string) $number, '0', 0);
    }
122216
protected static function array_nth(array $a, $n) {
        $keys = array_keys($a);
        if ($n < 0 or $n > count($keys) - 1) {
            return null;
        }
        $key = $keys[$n];
        return $a[$key];
    }
542959
public function setNum(int $n): void
    {
        $this->num     = $n;
        $this->numText = $n . ' ';
    }