Converts from any currency to any currency
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)
1183971
def get_conversion_rate(from_currency: str, to_currency: str) -> Decimal:
    
    reverse_rate = False
    if to_currency == BASE_CURRENCY:
        # Fetch exchange rate for base currency and use 1 / rate for conversion
        rate_currency = from_currency
        reverse_rate = True
    else:
        rate_currency = to_currency
    rate = get_rate_from_db(rate_currency)

    if reverse_rate:
        conversion_rate = Decimal(1) / rate
    else:
        conversion_rate = rate
    return conversion_rate
271527
public function convert($amount, $from_currency, $to_currency)
    {
        return $this->currency->convert($amount, $from_currency, $to_currency);
    }
1006579
function get(currency, callback) {
  if(['BTC', 'USD', 'AUD', 'NZD', 'CAD', 'EUR', 'GBP', 'SGD', 'HKD', 'CHF', 'JPY'].indexOf(currency) === -1) {
    throw new Error('specified currency is not supported');
  }

  if(!util.isFunction(callback)) {
    throw new Error('callback must be a function');
  }

  var resource = this.coinjar.personal.api_endpoint +
    '/v1/fair_rate/' +
    currency +
    '.json';

  request.get(resource)
    .auth(this.coinjar.personal.auth_token)
    .end(function (response) {
      if(isResponseError(response, callback)) { return; }
      return callback(null, response.body);
    });
}
398197
def ask(currency_code, price, amount, limit = nil, counter_currency_code = "jpy")
            return trade(currency_code, price, amount, "ask", limit, counter_currency_code)
        end
1285192
public static Currency toCurrency(String name) {
        try {
            return Currency.getInstance(name);
        } catch (IllegalArgumentException iae) {
            if (name.length() <= 3) {
                for (Currency c : Currency.getAvailableCurrencies()) {
                    if (matchesCurrency(name, c)) {
                        return c;
                    }
                }
            }
            return toFallbackCurrency(name, iae);
        }
    }
884620
def currency=(currency)
      validator = EnumAttributeValidator.new('String', ["UNKNOWN_CURRENCY", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "USS", "UYI", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XTS", "XXX", "YER", "ZAR", "ZMK", "ZMW", "BTC"])
      unless validator.valid?(currency)
        fail ArgumentError, "invalid value for 'currency', must be one of #{validator.allowable_values}."
      end
      @currency = currency
    end
1248086
def to(self, currency):
        """"""
        if currency == self._currency:
            return self
        rate = xrates.quotation(self._currency, currency)
        if rate is None:
            raise ExchangeRateNotFound(xrates.backend_name,
                                         self._currency, currency)
        amount = self._amount * rate
        return self.__class__(amount, currency)
101129
def currency_multiplier(src_currency, dest_currency):
    ''
    if src_currency == 'USD':
        return 1.0
    usd_mult = currency_rates()[src_currency]
    if dest_currency == 'USD':
        return usd_mult
    return usd_mult/currency_rates()[dest_currency]
1049986
def base_convert_money(amount, currency_from, currency_to):
    
    source = get_rate_source()

    # Get rate for currency_from.
    if source.base_currency != currency_from:
        rate_from = get_rate(currency_from)
    else:
        # If currency from is the same as base currency its rate is 1.
        rate_from = Decimal(1)

    # Get rate for currency_to.
    rate_to = get_rate(currency_to)

    if isinstance(amount, float):
        amount = Decimal(amount).quantize(Decimal('.000001'))

    # After finishing the operation, quantize down final amount to two points.
    return ((amount / rate_from) * rate_to).quantize(Decimal("1.00"))
772826
public static function fromNative()
    {
        $args = func_get_args();

        $amount   = new Integer($args[0]);
        $currency = Currency::fromNative($args[1]);

        return new static($amount, $currency);
    }
1355953
private function convert($a) {return call_user_func(
		[$this->currency(), lcfirst(substr(df_caller_f(), 1))], $a, $this->oq()
	);}
516423
def format_currency(amount, currency)
      
      currency = currency.upcase()
      # assuming that all currencies are split into 100 parts is probably wrong
      # on an i18n scale but it works for USD, EUR and LBP
      # TODO fix this maybe?
      amount = amount / 100.0
      options = {
        # use comma for euro 
        separator: currency == 'EUR' ? ',' : '.', 
        delimiter: currency == 'EUR' ? '.' : ',',
        format: currency == 'EUR' ? '%n %u' : '%u%n',
      }
      case currency
      when 'EUR'
        options[:unit] = '€' 
      when 'LBP'
        options[:unit] = '£'
      when 'USD'
        options[:unit] = '$'
      else
        options[:unit] = currency
      end
      return number_to_currency(amount, options)
    end
76680
def get_rate(currency):
    """"""
    source = get_rate_source()
    try:
        return Rate.objects.get(source=source, currency=currency).value
    except Rate.DoesNotExist:
        raise CurrencyConversionException(
            "Rate for %s in %s do not exists. "
            "Please run python manage.py update_rates" % (
                currency, source.name))
913373
public static Currency getInstance(String currencyCode) {

    Currency currency = getInstanceNoCreate(currencyCode.toUpperCase());

    if (currency == null) {
      return createCurrency(currencyCode.toUpperCase(), null, null);
    } else {
      return currency;
    }
  }
1228739
def get_value_in_base_currency(self) -> Decimal:
        
        # check if the currency is the base currency.
        amt_orig = self.get_value()
        # Security currency
        sec_cur = self.get_currency()
        #base_cur = self.book.default_currency
        cur_svc = CurrenciesAggregate(self.book)
        base_cur = cur_svc.get_default_currency()

        if sec_cur == base_cur:
            return amt_orig

        # otherwise recalculate
        single_svc = cur_svc.get_currency_aggregate(sec_cur)
        rate = single_svc.get_latest_rate(base_cur)

        result = amt_orig * rate.value
        return result
199387
def from_unit_to_satoshi(self, value, unit='satoshi'):
        
        if not unit or unit == 'satoshi':
            return value
        if unit == 'bitcoin' or unit == 'btc':
            return value * 1e8

        # assume fiat currency that we can convert
        convert = get_current_price(self.crypto, unit)
        return int(value / convert * 1e8)