Convert from value to all compatible units
@param number $decimals
@param bool $round
@return array
@throws InvalidArgumentException
506369
public function toAll($decimals = null, $round = true)
    {
        if (!isset($this->value)) {
            throw new InvalidArgumentException('From value not set');
        }

        if (empty($this->base_unit)) {
            throw new InvalidArgumentException('No from unit set');
        }

        $units = array();

        foreach ($this->units as $key => $data) {
            if ($data['base'] == $this->base_unit) {
                array_push($units, $key);
            }
        }

        return $this->toMany($units, $decimals, $round);
    }
554512
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
    {
        return $this->numberFormat($this->tax, $decimals, $decimalPoint, $thousandSeperator);
    }
920072
public static function round($number = false, $decimals = false) {

        if($number) {

            return number_format((float)$number, $decimals);
        }

        return false;
    }
603399
public static function benchScript($decimals = 3) : float
    {
        return (float) sprintf(
            '%0.'.(int) $decimals.'f',
            (microtime(true) - $_SERVER['REQUEST_TIME_FLOAT'])
        );
    }
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;
    }
806057
public function tax($decimals = null, $decimalPoint = null, $thousandSeperator = null)
    {
        $content = $this->getContent();

        $tax = $content->reduce(function ($tax, CartItem $cartItem) {
            return $tax + ($cartItem->qty * $cartItem->tax);
        }, 0);

        return $this->numberFormat($tax, $decimals, $decimalPoint, $thousandSeperator);
    }
1318619
public static function percentage($number1 = false, $number2 = false, $decimals = 2) {

        if($number1 && $number2) {

            return self::round(($number1 / $number2) * 100, $decimals);
        }

        return false;
    }
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;
	}
777085
public function getPercentage($round = true)
    {
        if ($this->numApprovedTranslations === 0 || $this->numTranslatable === 0) {
            $result = $round ? 0 : 0.0;
        } elseif ($this->numApprovedTranslations === $this->numTranslatable) {
            $result = $round ? 100 : 100.0;
        } else {
            $result = $this->numApprovedTranslations * 100.0 / $this->numTranslatable;
            if ($round) {
                $result = max(1, min(99, (int) round($result)));
            }
        }

        return $result;
    }
932525
public static function decimal( $value, $decimals = 2 )
	{
		$nf = new \NumberFormatter(\Locale::getDefault(), \NumberFormatter::DECIMAL);
		$nf->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $decimals);
		return $nf->format($value);
	}
335649
public function numberFormat($decimals, $decimalPoint, $thousandSeparator)
    {
        return $this->addRule(new FilterRule\NumberFormat($decimals, $decimalPoint, $thousandSeparator));
    }
405159
public function setRounds($rounds)
    {
        if (!is_numeric($rounds)) {
            throw new InvalidArgumentException("Expected rounds to be of numeric value. ", 400);
        }

        $this->rounds = (int) $rounds;

        return $this;
    }
117282
public function number($number, $decimals = null)
    {
        return number_format(
            (float) $number,
            $decimals,
            $this->getSymbol(self::DECIMAL_MARK),
            $this->getSymbol(self::THOUSANDS_SEPARATOR)
        );
    }
979379
public static function format($value, int $decimals = 2): ?string {
        if (!\is_numeric($value)) {
            return null;
        }
        return \number_format($value, $decimals);
    }
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());
    }
218344
public function out($decimals = 2, $decPoint = '.', $thousandSep = ',')
    {
        return $this->format($decimals, $decPoint, $thousandSep) . ' ' . $this->unit;
    }
522764
public static function _toReadableSize($size, $decimals = '.') {
		$size = parent::toReadableSize($size);
		if ($decimals !== '.') {
			$size = str_replace('.', $decimals, $size);
		}
		return $size;
	}