Convert the start value to the given unit.
Accepts an optional precision for how many significant digits to
retain

@param $unit
@param int|null $precision
@return float
554580
public function to($unit, $precision = null)
    {
        $fromUnit = UnitResolver::resolve($this->from);
        $toUnit = UnitResolver::resolve($unit);
        $this->setBase($unit);
        $base = $this->getBase() == 2 ? 1024 : 1000;
        //some funky stuff with negative exponents and pow
        if ($toUnit > $fromUnit)
            return $this->div($this->start, pow($base, $toUnit - $fromUnit), $precision);
        return $this->mul($this->start, pow($base, $fromUnit - $toUnit), $precision);
    }
1017096
public function ceilf($value, $precision = null) {

        $precision        = isset($precision) ? (int)$precision : $this->config->get('price.default_precision');
        $precision_factor = $precision == 0 ? 1 : pow(10, $precision);
        $tmp              = $value * $precision_factor;
        $tmp2             = (string)$tmp;

        // Si la valeur actuelle a déjà la précision désirée.
        if (strpos($tmp2, '.') === false && strpos($tmp2, ',') === false) {
            return ($value);
        }
        if ($tmp2[strlen($tmp2) - 1] == 0) {
            return $value;
        }

        return ceil($tmp) / $precision_factor;
    }
631755
public function roundUnit($unit, $precision = 1, $function = 'round')
    {
        $metaUnits = [
            // @call roundUnit
            'millennium' => [static::YEARS_PER_MILLENNIUM, 'year'],
            // @call roundUnit
            'century' => [static::YEARS_PER_CENTURY, 'year'],
            // @call roundUnit
            'decade' => [static::YEARS_PER_DECADE, 'year'],
            // @call roundUnit
            'quarter' => [static::MONTHS_PER_QUARTER, 'month'],
            // @call roundUnit
            'millisecond' => [1000, 'microsecond'],
        ];
        $normalizedUnit = static::singularUnit($unit);
        $ranges = array_merge(static::getRangesByUnit(), [
            // @call roundUnit
            'microsecond' => [0, 999999],
        ]);
        $factor = 1;
        if (isset($metaUnits[$normalizedUnit])) {
            [$factor, $normalizedUnit] = $metaUnits[$normalizedUnit];
        }
        $precision *= $factor;

        if (!isset($ranges[$normalizedUnit])) {
            throw new InvalidArgumentException("Unknown unit '$unit' to floor");
        }

        $found = false;
        $fraction = 0;
        $arguments = null;
        $factor = $this->year < 0 ? -1 : 1;
        $changes = [];

        foreach ($ranges as $unit => [$minimum, $maximum]) {
            if ($normalizedUnit === $unit) {
                $arguments = [$this->$unit, $minimum];
                $fraction = $precision - floor($precision);
                $found = true;

                continue;
            }

            if ($found) {
                $delta = $maximum + 1 - $minimum;
                $factor /= $delta;
                $fraction *= $delta;
                $arguments[0] += $this->$unit * $factor;
                $changes[$unit] = round($minimum + ($fraction ? $fraction * call_user_func($function, ($this->$unit - $minimum) / $fraction) : 0));
                // Cannot use modulo as it lose double precision
                while ($changes[$unit] >= $delta) {
                    $changes[$unit] -= $delta;
                }
                $fraction -= floor($fraction);
            }
        }

        [$value, $minimum] = $arguments;
        /** @var CarbonInterface $result */
        $result = $this->$normalizedUnit(floor(call_user_func($function, ($value - $minimum) / $precision) * $precision + $minimum));
        foreach ($changes as $unit => $value) {
            $result = $result->$unit($value);
        }

        return $result;
    }
379735
public static function fromDecimal(Decimal $decValue, int $scale = null): Decimal
    {
        self::paramsValidation($decValue, $scale);

        // This block protect us from unnecessary additional instances
        if ($scale === null || $scale >= $decValue->scale) {
            return $decValue;
        }

        return new static(
            self::innerRound($decValue->value, $scale),
            $scale
        );
    }
999420
public static function roundValues(array $data, $precision = 2)
    {
        return self::filterValuesRecursively($data, function($value) use ($precision) {
            $value = is_numeric($value) ? round($value, $precision) : $value;
            $value = empty($value) ? 0 : $value;

            return $value;
        });
    }
715931
public static function convertMetric( $value, $from, $to, $precision = null ) {
        switch ($from . $to) {
            case 'incm':
                $value *= 2.54;
                break;
            case 'inmm':
                $value *= 25.4;
                break;
            case 'inpt':
                $value *= 72;
                break;
            case 'cmin':
                $value /= 2.54;
                break;
            case 'cmmm':
                $value *= 10;
                break;
            case 'cmpt':
                $value *= 72 / 2.54;
                break;
            case 'mmin':
                $value /= 25.4;
                break;
            case 'mmcm':
                $value /= 10;
                break;
            case 'mmpt':
                $value *= 72 / 25.4;
                break;
            case 'ptin':
                $value /= 72;
                break;
            case 'ptcm':
                $value *= 2.54 / 72;
                break;
            case 'ptmm':
                $value *= 25.4 / 72;
                break;
        }

        if ( !is_null($precision) ) {
            $value = round($value, $precision);
        }

        return $value;
    }
888377
protected function unit(&$unit)
    {
        if ($this->match('([0-9]*(\.)?[0-9]+)([%a-zA-Z]+)?', $m)) {
            $unit = new Node\Number($m[1], empty($m[3]) ? '' : $m[3]);

            return true;
        }

        return false;
    }
105421
public function decimal($column, $precision = 8, $scale = 2)
    {
        return $this->table->addColumn($column, Type::DECIMAL, compact('precision', 'scale'));
    }
741223
public function get(?string $unit = null): int
    {
        if (null === $this->value) {
            $this->value = $this->stringToBytes(ini_get('upload_max_filesize'));
        }
        $value = $this->value;

        switch ($unit) {
            case self::GIGABYTES:
                $value /= 1024;
            case self::MEGABYTES:
                $value /= 1024;
            case self::KILOBYTES:
                $value /= 1024;
            case self::BYTES:
            default:
        }

        return $value;
    }
1272148
public function format($bytes, $precision = null)
    {
        // Use default precision when not specified.
        $precision === null && $precision = $this->getPrecision();

        $log = log($bytes, $this->getBase());
        $exponent = $this->hasFixedExponent() ? $this->getFixedExponent() : max(0, $log|0);
        $value = round(pow($this->getBase(), $log - $exponent), $precision);
        $units = $this->getUnitDecorator()->decorate($exponent, $this->getBase(), $value);

        return trim(sprintf($this->sprintfFormat, $this->formatValue($value, $precision), $units));
    }
1038244
public function setPrecision($precision)
    {
        if (!empty($precision) && ctype_digit(strval($precision))) {
            $this->precision = (int) $precision;
        }

        return $this;
    }
269767
public function startOf($unit, ...$params)
    {
        $ucfUnit = ucfirst(static::singularUnit($unit));
        $method = "startOf$ucfUnit";
        if (!method_exists($this, $method)) {
            throw new InvalidArgumentException("Unknown unit '$unit'");
        }

        return $this->$method(...$params);
    }
214377
public function roundUp(int $precision = 0): Utility
    {
        return $this->round($this->number, $precision, PHP_ROUND_HALF_UP);
    }
430339
public static final double round(double value, double precision)
   {
      precision = Math.pow(10, precision);
      return Math.round(value * precision) / precision;
   }
1256221
public static function create($value, int $scale = null): Decimal
    {
        if (\is_int($value)) {
            return self::fromInteger($value);
        } elseif (\is_float($value)) {
            return self::fromFloat($value, $scale);
        } elseif (\is_string($value)) {
            return self::fromString($value, $scale);
        } elseif ($value instanceof Decimal) {
            return self::fromDecimal($value, $scale);
        } else {
            throw new \TypeError(
                'Expected (int, float, string, Decimal), but received ' .
                (\is_object($value) ? \get_class($value) : \gettype($value))
            );
        }
    }
1319447
public function convertBaseToStandard($baseUnit, $value)
    {
        if (!isset($this->config[$this->family]['units'][$baseUnit])) {
            throw new UnknownMeasureException(
                sprintf(
                    'Could not find metric unit "%s" in family "%s"',
                    $baseUnit,
                    $this->family
                )
            );
        }
        $conversionConfig = $this->config[$this->family]['units'][$baseUnit]['convert'];
        $convertedValue = $value;

        foreach ($conversionConfig as $operation) {
            foreach ($operation as $operator => $operand) {
                $convertedValue = $this->applyOperation($convertedValue, $operator, $operand);
            }
        }

        return $convertedValue;
    }
712666
public function round($value, $currency = null)
    {
        return round($value / $this->interval, $this->precision) * $this->interval;
    }