Customer balance should be greater or equal to transaction amount.

@param float $balance
@param float $amount
@param bool $useDelta use some delta in values comparison (currency conversion gap)
@return bool
549552
private function validateCustomerBalance($balance, $amount, $useDelta = false)
    {
        if ($useDelta) {
            $result = (($balance + self::CONVERSION_DELTA) >= $amount);
        } else {
            $result = ($balance >= $amount);
        }
        return $result;
    }
1337592
public function round($amount, array $currency)
    {
        if (empty($currency['rounding_step'])) {
            return round($amount, $currency['decimals']);
        }

        $modifier = 1 / $currency['rounding_step'];
        return round($amount * $modifier) / $modifier;
    }
51775
protected function convertAmount($amount, $convert = false)
    {
        if (!$convert) {
            return $amount;
        }

        return $amount * $this->currency->getSubunit();
    }
543378
public function canPay($amount, $userId)
    {
        $balance = config('laravel_balance.user')::find($userId)->balance();

        return ($balance < $amount) ? false : true;
    }
1324686
def get_amount_arrears_balance(self, billing_cycle):
        """"""
        return self.to_account.balance(
            transaction__date__lt=billing_cycle.date_range.lower,
        )
271527
public function convert($amount, $from_currency, $to_currency)
    {
        return $this->currency->convert($amount, $from_currency, $to_currency);
    }
774859
def get_avg_price_fifo(self) -> Decimal:
        
        balance = self.get_quantity()
        if not balance:
            return Decimal(0)

        paid = Decimal(0)
        accounts = self.get_holding_accounts()
        # get unused splits (quantity and total paid) per account.
        for account in accounts:
            splits = self.get_available_splits_for_account(account)

            for split in splits:
                paid += split.value

        avg_price = paid / balance
        return avg_price
857859
public function percent(&$amount, array &$components, array $price_rule)
    {
        $value = $amount * ($price_rule['value'] / 100);
        $components[$price_rule['price_rule_id']] = array('rule' => $price_rule, 'price' => $value);
        return $amount += $value;
    }
726804
public function hold($amount, $desc='Hold', $cat, $ref)
	{
		$amount = $this->_amountCheck($amount);

		if ($this->getError())
		{
			echo $this->getError();
			return;
		}

		// Current order processing workflow (which requires manual order fulfillment on the backend) prevents race
		// condition with the check and update below from corrupting user point balance, but if
		// but if workflow is ever changed, a table/row level lock would need to be added to this function
		// and error code added to deal with multiple orders with insufficient balances.
		//
		// See https://hubzero.org/support/ticket/234 for details

		if ($this->_creditCheck($amount))
		{
			$this->credit += $amount;

			if (!$this->_save('hold', $amount, $desc, $cat, $ref))
			{
				echo $this->getError();
			}
		}
		else
		{
			echo $this->getError();
		}
	}
955153
def recalculate_balance(stmt):
    

    total_amount = sum(sl.amount for sl in stmt.lines)

    stmt.start_balance = stmt.start_balance or D(0)
    stmt.end_balance = stmt.start_balance + total_amount
    stmt.start_date = min(sl.date for sl in stmt.lines)
    stmt.end_date = max(sl.date for sl in stmt.lines)
496620
public function equals(Money $money)
  {
    return $this->isSameCurrency($money) && $this->cents == $money->cents;
  }
589698
public function smartConvert($amount, $from, $to)
    {
        // Smart Convert Logic
        Log::info('Running Smart Currency Conversion');

        if ($this->_currencyLayerApiKey != NULL)
        {
            $conv = self::currencyLayerConvert($amount, $from, $to);

            if(!$conv)
            {
                if ($this->_exchangeRateApiKey != NULL)
                {
                    return self::exchangeRateConvert($amount, $from, $to);
                }
                return false;
            }

            return $conv;
        }
        elseif ($this->_exchangeRateApiKey != NULL)
        {
            return self::exchangeRateConvert($amount, $from, $to);
        }

        return false;
    }
651454
public function format($amount, $currency_code, $decimal = true, $full = true)
    {
        $currency = $this->currency->get($currency_code);

        if (empty($currency)) {
            return 'n/a';
        }

        if ($decimal) {
            $amount = $this->decimal($amount, $currency_code);
        }

        // Pass the amount to the currency template as %price variable
        $currency['price'] = $this->formatNumber($amount, $currency);

        if ($full) {
            return $this->formatTemplate($amount, $currency);
        }

        return $amount < 0 ? '-' . $currency['price'] : $currency['price'];
    }
1238773
public function formatAmount($amount, $currency)
    {
        switch ($currency) {
            case "JPY":
            case "IDR":
            case "KRW":
            case "BYR":
            case "VND":
            case "CVE":
            case "DJF":
            case "GNF":
            case "PYG":
            case "RWF":
            case "UGX":
            case "VUV":
            case "XAF":
            case "XOF":
            case "XPF":
            case "GHC":
            case "KMF":
                $format = 0;
                break;
            case "MRO":
                $format = 1;
                break;
            case "BHD":
            case "JOD":
            case "KWD":
            case "OMR":
            case "LYD":
            case "TND":
                $format = 3;
                break;
            default:
                $format = 2;
                break;
        }

        return (int)number_format($amount, $format, '', '');
    }
866095
public static function getStoreAmountOfCurrency($amount, $currencyCode) {
        $currencyCode   = strtoupper($currencyCode);
        $amount         = (int) $amount;

        if( in_array($currencyCode, self::FULL_VALUE_CURRENCIES, true) ) {
            return (float) $amount;
        }

        if( in_array($currencyCode, self::DIV_1000_VALUE_CURRENCIES, true) ) {
            return (float) ($amount / self::DIV_1000);
        }

        return (float) ($amount / self::DIV_100);
    }
548234
public function counter($column, $amount = 1): ResultInterface
    {
        $this->update = $this->getTableName();
        if (is_array($column)) {
            $this->counterValues = $column;
        } else {
            $this->counterValues = [$column => $amount];
        }

        return $this->execute();
    }
1071236
public function convert($amount, $from_currency, $to_currency)
    {
        if ($from_currency === $to_currency) {
            return $amount; // Nothing to convert
        }

        $currency = $this->get($from_currency);
        $target_currency = $this->get($to_currency);

        $exponent = $target_currency['decimals'] - $currency['decimals'];
        $amount *= pow(10, $exponent);

        return $amount * ($currency['conversion_rate'] / $target_currency['conversion_rate']);
    }