If the fraction of the amount is 0.5, then return the even integer nearest to the amount.

@param string $amount the amount to round

@return string
324850
private static function roundHalfToEven($amount)
    {
        $result = self::roundToNearestIntegerIgnoringTies($amount);

        if (null == $result) {
            $truncated = self::roundHalfTowardsZero($amount);

            if (0 == bcmod($truncated, '2')) { // Even
                $result = $truncated;
            } else {
                $result = self::roundHalfAwayFromZero($amount);
            }
        }

        return $result;
    }
940492
protected function parseAmountDecimalSeparator($amount) {
    $decimal_separator_counts = [];
    foreach ($this->decimalSeparators as $decimal_separator) {
      $decimal_separator_counts[$decimal_separator] = \mb_substr_count($amount, $decimal_separator);
    }
    $decimal_separator_counts_filtered = array_filter($decimal_separator_counts);
    if (count($decimal_separator_counts_filtered) > 1 || reset($decimal_separator_counts_filtered) !== FALSE && reset($decimal_separator_counts_filtered) != 1) {
      return FALSE;
    }
    return str_replace($this->decimalSeparators, '.', $amount);
  }
1091428
private function precision($number)
        {
            $precision = 0;
            $pt = strpos($number, '.');

            if ($pt !== false) {
                $precision = -(strlen($number) - $pt - 1);
            }

            return pow(10, $precision) / 2;
        }
666485
private static function roundUp($amount)
    {
        $result = self::roundTowardsZero($amount);

        if (1 == bccomp($amount, '0', self::BCSCALE) && 0 != bccomp($amount, $result, self::BCSCALE)) {
            $result = bcadd($result, '1', self::BCSCALE);
        }

        return $result;
    }
168753
private static function roundAwayFromZero($amount)
    {
        $result = self::roundTowardsZero($amount);

        if (0 != bccomp($amount, $result, self::BCSCALE)) {
            if (1 == bccomp($amount, '0', self::BCSCALE)) {
                $result = bcadd($result, '1', self::BCSCALE);
            } elseif (-1 == bccomp($amount, '0', self::BCSCALE)) {
                $result = bcsub($result, '1', self::BCSCALE);
            }
        }

        return $result;
    }
499235
public static function toCents($amount)
    {
        /*
         * There's probably a better way, but this is what i could come up with
         * to avoid rounding errors
         * todo: search for a better way
         */

        if (!is_float($amount)) {
            $type = gettype($amount);

            throw new \UnexpectedValueException("Needs a float! not $type");
        }

        //handle locales
        $locale = localeconv();

        $amount = str_replace($locale['mon_thousands_sep'], '', $amount);
        $amount = str_replace($locale['mon_decimal_point'], '.', $amount);
        $amount = str_replace($locale['decimal_point'], '.', $amount);

        $parts = explode('.', "$amount");

        // handle the case where $amount has a .0 fraction part
        if (count($parts) == 1) {
            $parts[] = '00';
        }

        list($whole, $fraction) = $parts;

        /*
         * since the documentation only mentions decimals with a precision of two
         * and doesn't specify any rounding method i'm truncating the number
         *
         * the str_pad is to handle the case where $amount is, for example, 6.9
         */
        $fraction = str_pad(substr($fraction, 0, 2), 2, '0');

        $whole = (int) $whole * 100;
        $fraction = (int) $fraction;

        return $whole + $fraction;
    }
84908
public function asFloat(Money $money)
    {
        $amount = $money->getAmount();
        $amount = (float) $amount;
        $amount = $amount / pow(10, $this->decimals);

        return $amount;
    }
671173
public static function checkAmount($amount)
    {
        if ($amount < 0 || $amount === null) {
            throw new HpsInvalidRequestException(
                HpsExceptionCodes::INVALID_AMOUNT,
                'Must be greater than or equal to 0.',
                'amount'
            );
        }
        $amount = preg_replace('/[^0-9\.]/', '', $amount);
        return sprintf("%0.2f", round($amount, 3));
    }
322243
def _round(num):
    
    deci = num - math.floor(num)
    if deci > 0.8:
        return int(math.floor(num) + 1)
    else:
        return int(math.floor(num))
964397
function getNumericPresentation( &$entry )
	{
		if ( isset( $entry['precision'] ) && strval( $entry['precision'] ) === '0' )
		{
			return NAN;
		}

		// Using PHP_ROUND_HALF_EVEN see XBRL 2.1 section 4.6.7.2
		$decimals = $this->getDecimals( $entry );
		return $decimals == INF
			? $entry['value']
			: round( $entry['value'], $this->getDecimals( $entry ), PHP_ROUND_HALF_EVEN );
	}
687652
public function saturate($amount)
    {
        if ($amount < 0 || $amount > 100) {
            throw new InvalidArgumentException('The given amount must be between 0 and 100');
        }
        $amount /= 100;
        $this->saturation += (100 - $this->saturation) * $amount;

        return $this;
    }
1130492
public function setAmount($amount)
    {
        if (!Icepay_Parameter_Validation::amount($amount))
            throw new Exception('Please enter a valid amount (in cents)', 1003);

        $this->amount = $amount;
        return $this;
    }
1128809
public function multiply($number)
  {
    return Money::init((int) round($this->cents * $number, 0, PHP_ROUND_HALF_EVEN), $this->currency->getIsoCode());
  }
1142021
public static function fraction($num, float $precision=0.0001) {
		ref\format::fraction($num, $precision);
		return $num;
	}
1306274
final public function limit(int $amount = null)
    {
        $this->limitAmount = $amount === null ? null : $amount;

        return $this;
    }
1228256
public function subtract(Money $money)
    {
        if (!$this->currency->equals($money->getCurrency())) {
            throw new CurrencyMismatchException($this.' does not match '.$money);
        }

        $amount = bcsub($this->amount, $money->getAmount(), self::BCSCALE);

        return self::valueOf($amount, $this->currency);
    }
718085
public function getInWordsFloat($amount)
    {
        $words = array();

        $intPart = (int)$amount;
        $pointVariants = array('целая', 'целых', 'целых');
        $words[] = $this->sumString($intPart, RUtils::FEMALE, $pointVariants);

        $remainder = $this->_getFloatRemainder($amount);
        $signs = strlen($remainder) - 1;
        $words[] = $this->sumString($remainder, RUtils::FEMALE, self::$_FRACTIONS[$signs]);

        $result = trim(implode(' ', $words));
        return $result;
    }