Calculates the amount in base currency
484294
def get_amount_in_base_currency(self, currency: str, amount: Decimal) -> Decimal:
        
        assert isinstance(amount, Decimal)

        # If this is already the base currency, do nothing.
        if currency == self.get_default_currency().mnemonic:
            return amount

        agg = self.get_currency_aggregate_by_symbol(currency)
        if not agg:
            raise ValueError(f"Currency not found: {currency}!")

        # TODO use pricedb for the price.
        rate_to_base = agg.get_latest_price()
        if not rate_to_base:
            raise ValueError(f"Latest price not found for {currency}!")
        assert isinstance(rate_to_base.value, Decimal)

        result = amount * rate_to_base.value
        return result
513353
function getCurrencySymbol(code, format, locale) {
    if (locale === void 0) { locale = 'en'; }
    var currency = getLocaleCurrencies(locale)[code] || CURRENCIES_EN[code] || [];
    var symbolNarrow = currency[1 /* SymbolNarrow */];
    if (format === 'narrow' && typeof symbolNarrow === 'string') {
        return symbolNarrow;
    }
    return currency[0 /* Symbol */] || code;
}
502115
def convert(amount, from_code, to_code, decimals=2, qs=None):
    """"""
    if from_code == to_code:
        return amount

    if qs is None:
        qs = get_active_currencies_qs()

    from_, to = qs.get(code=from_code), qs.get(code=to_code)

    amount = D(amount) * (to.factor / from_.factor)
    return price_rounding(amount, decimals=decimals)
374943
public static function GetBaseCurrency()
    {
        static $oInstance = null;
        if (null === $oInstance) {
            $oInstance = TdbPkgShopCurrency::GetNewInstance();
            if (false === $oInstance->LoadFromField('is_base_currency', '1')) {
                $oInstance = false;
            }
        }

        return $oInstance;
    }
1227322
def currency(s=''):
    ''
    if isinstance(s, str):
        s = ''.join(ch for ch in s if ch in floatchars)
    return float(s) if s else TypedWrapper(float, None)
766436
public function calculatePriceTax()
    {
        $expression = $this->tax->calculator;

        $parser = new StdMathParser();
        $AST = $parser->parse($this->tax->calculator);
        $evaluator = new Evaluator();
        $evaluator->setVariables(['x' => $this->calculatePriceTaxable()->getAmount() / 100]);
        $value = $AST->accept($evaluator);
        $money = new Money(round($value, 2, PHP_ROUND_HALF_UP) * 100, new Currency($this->invoice->currency));

        return $money;
    }
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;
    }
126462
def currency(money):
    
    decimals = getattr(settings, 'MIDNIGHT_CATALOG_DECIMALS', 2)
    money = round(float(money), decimals)
    symbol = getattr(settings, 'MIDNIGHT_CATALOG_CURRENCY', 'руб')
    if decimals > 0:
        formatted = (str("%0."+str(decimals)+"f") % money)[-decimals-1:]
    else:
        formatted = ""
    return "%s%s %s" % (intcomma(int(money)), formatted, symbol)
1050358
def get_cash_balance_with_children(self, root_account: Account, currency: Commodity) -> Decimal:
        
        total = Decimal(0)
        svc = CurrenciesAggregate(self.book)

        # get all child accounts in a list
        cash_balances = self.load_cash_balances_with_children(
            root_account.fullname)
        # get the amounts
        for cur_symbol in cash_balances:
            # Currency symbol
            value = cash_balances[cur_symbol]["total"]

            if cur_symbol != currency.mnemonic:
                # Convert the amount to the given currency.
                other_cur = svc.get_by_symbol(cur_symbol)

                cur_svc = svc.get_currency_aggregate(other_cur)

                rate = cur_svc.get_latest_rate(currency)
                value = value * rate.value

            total += value

        return total
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);
    }
1255746
function selectCurrency($val = '', $subset = 'EC') {
    $ec_currencies = array('CAD', 'EUR', 'GBP', 'JPY', 'USD', 'AUD', 'CHF', 'CZK', 'DKK', 'HKD', 'HUF', 'NOK', 'NZD', 'PLN', 'SEK', 'SGD', 'THB', 'MXN', 'ILS', 'PHP', 'TWD', 'BRL', 'MYR', 'TKD');
    $dp_currencies = array('CAD', 'EUR', 'GBP', 'JPY', 'USD', 'AUD');
    $paypalSupportedCurrencies = ($subset == 'EC') ? $ec_currencies : $dp_currencies;

    // if using Pro 2.0 (UK), only the 6 currencies are supported.
    $paypalSupportedCurrencies = (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK') ? $dp_currencies : $paypalSupportedCurrencies;

    $my_currency = substr(MODULE_PAYMENT_PAYPALWPP_CURRENCY, 5);
    if (MODULE_PAYMENT_PAYPALWPP_CURRENCY == 'Selected Currency') {
      $my_currency = ($val == '') ? $_SESSION['currency'] : $val;
    }

    if (!in_array($my_currency, $paypalSupportedCurrencies)) {
      $my_currency = (MODULE_PAYMENT_PAYPALWPP_MODULE_MODE == 'Payflow-UK') ? 'GBP' : 'USD';
    }
    return $my_currency;
  }
315174
def __calculate_current_value(self, asset_class: AssetClass):
        
        # Is this the final asset class, the one with stocks?
        if asset_class.stocks:
            # add all the stocks
            stocks_sum = Decimal(0)
            for stock in asset_class.stocks:
                # recalculate into base currency!
                stocks_sum += stock.value_in_base_currency

            asset_class.curr_value = stocks_sum

        if asset_class.classes:
            # load totals for child classes
            for child in asset_class.classes:
                self.__calculate_current_value(child)
                asset_class.curr_value += child.curr_value
1091927
def get_exchange_rate(base, target, *args, **kwargs):
    
    return Cryptonator().get_exchange_rate(base, target, *args, **kwargs)
658732
public function calculatePriceTaxable()
    {
        $money = new Money(round($this->price, 2, PHP_ROUND_HALF_UP) * 100, new Currency($this->invoice->currency));

        return $money;
    }
34462
def get_exchange_rate(self, base, target, raise_errors=True):
        """"""
        assert base and target

        base, target = base.lower(), target.lower()

        r = self.session.get(API_SIMPLE_TICKER.format(base, target))
        if r.status_code != requests.codes.ok:
            if not raise_errors:
                return None
            raise CryptonatorException(
                ("An error occurred while getting requested exchange rate "
                 "({} from Cryptonator).").format(r.status_code)
            )

        j = r.json()
        if not j['success'] or j['error']:
            if not raise_errors:
                return None
            raise CryptonatorException(
                ("An error occurred while getting requested exchange rate ({}, {})"
                 "('{}').").format(base, target, j['error'])
            )

        return float(j['ticker']['price'])
547924
def rate(self, from_currency, to_currency, date):
        """"""
        return (1 / self.backend.get_rate(from_currency, date)) * self.backend.get_rate(
            to_currency, date
        )
1037499
public function getAmountCents()
    {
        if ($this->getNotForPayment()) {
            return 'XX';
        }
        $amount = $this->getAmount();
        $francs = intval($amount);
        $cents = round(($amount - $francs) * 100);
        return str_pad($cents, 2, '0', STR_PAD_LEFT);
    }