Rounds a value.

@param int|float $value     The value to round
@param int       $precision The number of decimal digits to round to

@return int|float The rounded value
347547
private function round($value, $precision)
    {
        $precision = $this->getUninitializedPrecision($value, $precision);

        $roundingModeAttribute = $this->getAttribute(self::ROUNDING_MODE);
        if (isset(self::$phpRoundingMap[$roundingModeAttribute])) {
            $value = round($value, $precision, self::$phpRoundingMap[$roundingModeAttribute]);
        } elseif (isset(self::$customRoundingList[$roundingModeAttribute])) {
            $roundingCoef = pow(10, $precision);
            $value *= $roundingCoef;
            $value = (float) (string) $value;

            switch ($roundingModeAttribute) {
                case self::ROUND_CEILING:
                    $value = ceil($value);
                    break;
                case self::ROUND_FLOOR:
                    $value = floor($value);
                    break;
                case self::ROUND_UP:
                    $value = $value > 0 ? ceil($value) : floor($value);
                    break;
                case self::ROUND_DOWN:
                    $value = $value > 0 ? floor($value) : ceil($value);
                    break;
            }

            $value /= $roundingCoef;
        }

        return $value;
    }
1082016
public static function fromFloat($float_value, $precision = null)
    {
        if ($precision === null) {
            $precision = static::$PRECISION;
        }

        // left of decimal point
        $rounded_float = intval(round($float_value));
        $big_integer_int = (new BigInt($rounded_float))->multiply(self::precisionUnitsAsBigInt(1, $precision));

        // right of decimal point
        $rounded_decimal = intval(round(floatval($float_value - $rounded_float) * pow(10, $precision)));
        $big_integer_decimal = new BigInt($rounded_decimal);

        // add the integer value and the decimal value
        return new static($big_integer_int->add($big_integer_decimal), $precision);
    }
1136516
public function toDecimal($value, int $precision = 12): float
    {
        if (is_numeric($value) === false) {
            return 0.0;
        }

        return round((float) $value, $precision);
    }
1349576
public static function inferPrecision( $value, $decimals )
	{
		if ( $decimals == "INF" ) return INF;
		if ( ! is_numeric( $value ) ) return false;

		$fValue = floatval( $value );

		if ( $value === false ) return false;
		if ( $decimals === "" ) return 0;

		$precision = 0;
		if ( preg_match( '/[-+]?[0]*([1-9]?[0-9]*)([.])?(0*)([1-9]?[0-9]*)?([eE])?([-+]?[0-9]*)?/', $value, $matches ) )
		{
			list( $all, $nonZeroInt, $period, $zeroDec, $nonZeroDec, $e, $exp ) = $matches;
			$precision = (
				$nonZeroInt
					? strlen( $nonZeroInt )
					: ( $nonZeroDec ? -strlen( $zeroDec ) : 0 )
				) + ( $exp ? intval( $exp ) : 0 ) + ( intval( $decimals ) );

			if ( $precision < 0 ) $precision = 0;
		}

		return $precision;
	}
311188
public static int getRounded(double value, int round)
    {
        Check.different(round, 0);

        return (int) Math.floor(value / round) * round;
    }
663219
public function readableSize($value, $precision = 0, $base = 1024)
    {
        $i = 0;
        if ($value < 1) {
            return '0';
        }

        $units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
        while (($value / $base) >= 1) {
            $value = $value / $base;
            $i++;
        }
        $unit = isset($units[$i]) ? $units[$i] : '?';
        return round($value, $precision) . $unit;
    }
863325
public static function round($op1, $precision = 0)
    {
        if (self::$_bcmathDisabled) {
            $op1 = round($op1, $precision);
            if (strpos((string) $op1, 'E') === false) {
                return self::normalize(round($op1, $precision));
            }
        }

        if (strpos($op1, 'E') !== false) {
            $op1 = self::floatalize($op1);
        }

        $op1    = trim(self::normalize($op1));
        $length = strlen($op1);
        if (($decPos = strpos($op1, '.')) === false) {
            $op1 .= '.0';
            $decPos = $length;
            $length += 2;
        }
        if ($precision < 0 && abs($precision) > $decPos) {
            return '0';
        }

        $digitsBeforeDot = $length - ($decPos + 1);
        if ($precision >= ($length - ($decPos + 1))) {
            return $op1;
        }

        if ($precision === 0) {
            $triggerPos = 1;
            $roundPos   = -1;
        } elseif ($precision > 0) {
            $triggerPos = $precision + 1;
            $roundPos   = $precision;
        } else {
            $triggerPos = $precision;
            $roundPos   = $precision -1;
        }

        $triggerDigit = $op1[$triggerPos + $decPos];
        if ($precision < 0) {
            // zero fill digits to the left of the decimal place
            $op1 = substr($op1, 0, $decPos + $precision) . str_pad('', abs($precision), '0');
        }

        if ($triggerDigit >= '5') {
            if ($roundPos + $decPos == -1) {
                return str_pad('1', $decPos + 1, '0');
            }

            $roundUp = str_pad('', $length, '0');
            $roundUp[$decPos] = '.';
            $roundUp[$roundPos + $decPos] = '1';

            if ($op1 > 0) {
                if (self::$_bcmathDisabled) {
                    return Zend_Locale_Math_PhpMath::Add($op1, $roundUp, $precision);
                }
                return self::Add($op1, $roundUp, $precision);
            } else {
                if (self::$_bcmathDisabled) {
                    return Zend_Locale_Math_PhpMath::Sub($op1, $roundUp, $precision);
                }
                return self::Sub($op1, $roundUp, $precision);
            }
        } elseif ($precision >= 0) {
            return substr($op1, 0, $decPos + ($precision ? $precision + 1: 0));
        }

        return (string) $op1;
    }
1124769
public static function float($value){

		$value = static::_nullValue($value);

		if($value !== null){

			// Avoid decimal separator nonsense
			$value = str_replace(',', '.', $value);
			$value = (float) $value;
		}

		return $value;
	}
785375
public function formatCurrency($value, $currency, $precision=2)
    {
        $newValue = trim($value, " \0\x0B$currency");
        if (!is_numeric($newValue)) {
            return $value;
        }

        $pattern = $this->getPattern($value, 'Intl_NumberFormatCurrency');

        if ($newValue == round($newValue)) {
            // if no fraction digits available, don't show any
            $value = $this->formatNumberWithPattern($pattern, $newValue, 0, 0);
        } else {
            // show given count of fraction digits otherwise
            $value = $this->formatNumberWithPattern($pattern, $newValue, $precision, $precision);
        }

        return str_replace('¤', $currency, $value);
    }
214377
public function roundUp(int $precision = 0): Utility
    {
        return $this->round($this->number, $precision, PHP_ROUND_HALF_UP);
    }
432248
public static String round(String value, int scale) {
        BigDecimal bd;
        try {
            bd = new BigDecimal(value);
            bd = bd.setScale(scale, RoundingMode.HALF_UP);
            return bd.toString();
        } catch (Exception e) {
            return null;
        }
    }
1110069
def round_to_int(number, precision):
    """"""
    precision = int(precision)
    rounded = (int(number) + precision / 2) // precision * precision
    return rounded
701471
public static function countDecimals(float $value)
    {
        // When the value when cast to an integer is about the same, return 0 decimal places. Otherwise count them.
        return (int) $value == $value ? 0 : (strlen($value) - strrpos($value, '.') - 1);
    }
1344170
public function setValue($value)
    {
        if (is_null($value)) {
            return $this->value = $value;
        }

        return $this->value = round($value, $this->scale);
    }
398746
public function setPrecision($precision)
	{
		$available = [self::PRECISION_FIXED, self::PRECISION_DOUBLE, self::PRECISION_FLOAT];
		
		if ( ! is_scalar($precision) || ! in_array($precision, $available, false))
		{
			throw new \InvalidArgumentException(sprintf('Wrong precision value for %s, available values are %s',
				(string) $precision, implode(', ', $available)));
		}
		
		$this->precision = (string) $precision;
		
		return $this;
	}
412179
private function round_($result, $precision) {
        if (abs($result) === INF) {
            return $result;
        }
        $str = strtolower((string) $result);
        if (strpos($str, 'e') !== false) {
            $r = explode('e', $str);
            $left = round((float) $r[0], (int) $precision);
            $right = $r[1];
            return (float) ($left.'e'.$right);
        }
        return round($result, (int) $precision);
    }
1225444
public static function formatNumber( $float, $unit = 1, $precision = 0 )
	{
		Deprecation::getInstance()->setExceptionVersion( '0.8' )
			->message(  'Use one of the other methods instead' );
		if( (int) $unit )
		{
			$float	= $float / $unit;
			if( is_int( $precision ) )
				$float	= round( $float, $precision );
		}
		return $float;
	}