Appends ROUND() function

@param string $column The column to round
@param float $decimals Specifies the number of decimals to be returned
@param string $alias Optional alias
@return \Krystal\Db\Sql\Db
553923
public function round($column, $decimals, $alias = null)
    {
        $this->queryBuilder->round($column, $decimals, $alias);
        return $this;
    }
74780
public function max($column, $alias = null)
    {
        $this->queryBuilder->max($column, $alias);
        return $this;
    }
1366071
public function len($column, $alias = null)
    {
        $this->queryBuilder->len($column, $alias);
        return $this;
    }
512880
public function addCount($column = '*', string $alias = null): self
    {
        return $this->addAggregate('COUNT', $column, $alias);
    }
964143
public function hasColumnAlias($alias)
    {
        return $this->hasAlias($alias) && $this->getExpression($this->getHash($alias)) instanceof Expr\Column;
    }
516436
public function sum(string $column, string $alias = null): string
    {
        if ($alias) {
            $alias = $this->quoteName($alias);
        }

        return 'SUM(' . $this->quoteName($column) . ')' . ($alias ? ' AS ' . $alias : '');
    }
740564
public function addSelect($columns) {
		if(is_array($columns))
			return $this->_addSelect($columns);

		$columns = explode(',', $columns);
		foreach($columns as $columnstr) {
			$columnstr = trim($columnstr);

			preg_match('/(.*?)\s+as\s+([a-z_][a-zA-Z0-9_]*)?$/i', $columnstr, $matches);
			if(isset($matches[2])) {
				$alias = $matches[2];
				$column = $matches[1];
			}
			else
				$alias = $column = $columnstr;

			if(isset($this->columns[$alias]))
				throw new \Exception('Column alias '.$alias.' is already used.');
			$this->columns[$alias] = $column;
		}

		return $this;
	}
920072
public static function round($number = false, $decimals = false) {

        if($number) {

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

        return false;
    }
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);
	}
1085532
public function count($column, $alias)
    {
        return $this->addSelectColumn(new Func\Count(new Expr\Column($column)), $alias);
    }
201871
public static function mathAdd($decimal1, $decimal2) {
        if (!is_numeric($decimal1)) {
            throw new Exception("decimal1 is not a numeric value: " . $decimal1);
        }

        if (!is_numeric($decimal2)) {
            throw new Exception("decimal2 is not a numeric value: " . $decimal2);
        }

        return round($decimal1 + $decimal2, StaticEb::$roundPrecision);
    }
1211451
public function to($unit, $decimals = null, $round = true)
    {
        if (!isset($this->value)) {
            throw new InvalidArgumentException('From value not set');
        }

        if (is_array($unit)) {
            return $this->toMany($unit, $decimals, $round);
        }

        $key = strtolower($unit);

        if (empty($this->units[$key]['base'])) {
            throw new OutOfBoundsException('Unit does not exist');
        }

        if (!isset($this->base_unit)) {
            $this->base_unit = $this->units[$key]['base'];
        }

        if ($this->units[$key]['base'] != $this->base_unit) {
            throw new InvalidArgumentException('Cannot convert between units of different types');
        }

        if (is_callable($this->units[$key]['conversion'])) {
            $result = $this->units[$unit]['conversion']($this->value, true);
        } else {
            $result = $this->value / $this->units[$key]['conversion'];
        }

        if (!isset($decimals)) {
            return $result;
        }

        if ($round) {
            return round($result, $decimals);
        }

        $shifter = $decimals ? pow(10, $decimals) : 1;
        return floor($result * $shifter) / $shifter;
    }
26427
public function addColumn(string $alias, Expr $column)
    {
        $this->aliasColumnMap[$alias] = $column;

        return $this;
    }
1194103
protected function _getFloatColumn(Column\Float $column)
    {
        if (is_null($column->getDecimal())) {
            return sprintf(
                '%s FLOAT(%s)',
                $column->getName(),
                $column->getDigits()
            );
        }

        return sprintf(
            '%s DECIMAL(%s, %s)',
            $column->getName(),
            $column->getDigits(),
            $column->getDecimal()
        );
    }
712666
public function round($value, $currency = null)
    {
        return round($value / $this->interval, $this->precision) * $this->interval;
    }
868616
public function max($column, $alias)
    {
        return $this->addSelectColumn(new Func\Max(new Expr\Column($column)), $alias);
    }
1202581
public function round($decimalDigits = null, $mode = self::ROUND_HALF_AWAY_FROM_ZERO)
    {
        if (null === $decimalDigits) {
            $decimalDigits = $this->currency->getDecimalDigits();
        }

        $factor = bcpow('10', $decimalDigits, self::BCSCALE);
        $amount = bcmul($this->amount, $factor, self::BCSCALE);

        switch ($mode) {
            case self::ROUND_UP:
                $result = self::roundUp($amount);
                break;
            case self::ROUND_DOWN:
                $result = self::roundDown($amount);
                break;
            case self::ROUND_TOWARDS_ZERO:
                $result = self::roundTowardsZero($amount);
                break;
            case self::ROUND_AWAY_FROM_ZERO:
                $result = self::roundAwayFromZero($amount);
                break;
            case self::ROUND_HALF_UP:
                $result = self::roundHalfUp($amount);
                break;
            case self::ROUND_HALF_DOWN:
                $result = self::roundHalfDown($amount);
                break;
            case self::ROUND_HALF_TOWARDS_ZERO:
                $result = self::roundHalfTowardsZero($amount);
                break;
            case self::ROUND_HALF_AWAY_FROM_ZERO:
                $result = self::roundHalfAwayFromZero($amount);
                break;
            case self::ROUND_HALF_TO_EVEN:
                $result = self::roundHalfToEven($amount);
                break;
            case self::ROUND_HALF_TO_ODD:
                $result = self::roundHalfToOdd($amount);
                break;
            default:
                throw new \InvalidArgumentException('Unknown rounding mode \''.$mode.'\'');
        }

        $result = bcdiv($result, $factor, self::BCSCALE);

        return self::valueOf($result, $this->currency);
    }