Convert all elements on the page marked up with data-convert attributes to the given currency.

@param currency
169055
function convert(currency) {
    // Store the current currency.
    var oldCurrency = Currency.currentCurrency;

    // Call convertAll with all possible formats. Currency.currentCurrency will be set as a side effect.
    Currency.convertAll(Currency.currentCurrency, currency, '[data-convert="money"]', 'money_format');
    Currency.convertAll(Currency.currentCurrency, currency, '[data-convert="money_with_currency"]', 'money_with_currency_format');
    Currency.convertAll(Currency.currentCurrency, currency, '[data-convert="money_without_currency"]', 'money_without_currency_format');

    // Save the chosen currency in a cookie.
    Currency.cookie.write(currency);

    // If there was a change in currency, fire the currency changed event.
    if(oldCurrency != currency) {
      $(document).trigger('currency.changed', [oldCurrency, currency]);
    }
  }
22909
@Override
    public Set<CurrencyUnit> getCurrencies(CurrencyQuery query) {
        Set<CurrencyUnit> result = new HashSet<>();
        for (Locale locale : query.getCountries()) {
            try {
                result.add(Waehrung.of(Currency.getInstance(locale)));
            } catch (IllegalArgumentException ex) {
                LOG.log(Level.WARNING, "Cannot get currency for locale '" + locale + "':", ex);
            }
        }
        for (String currencyCode : query.getCurrencyCodes()) {
            try {
                result.add(Waehrung.of(currencyCode));
            } catch (IllegalArgumentException ex) {
                LOG.log(Level.WARNING, "Cannot get currency '" + currencyCode + "':", ex);
            }
        }
        for (CurrencyProviderSpi spi : Bootstrap.getServices(CurrencyProviderSpi.class)) {
            result.addAll(spi.getCurrencies(query));
        }
        return result;
    }
1124176
@Override
    protected void registerCurrencies() throws Exception {
        parseCurrencies(loadFromFile("/org/joda/money/CurrencyData.csv"));
        parseCountries(loadFromFile("/org/joda/money/CountryData.csv"));
        parseCurrencies(loadFromFiles("META-INF/org/joda/money/CurrencyDataExtension.csv"));
        parseCountries(loadFromFiles("META-INF/org/joda/money/CountryDataExtension.csv"));
    }
845397
public static function parse($str, $currency = 'USD')
    {
        // get currency object
        $currency = (is_string($currency) ? new Currency($currency) : $currency);

        // remove HTML encoded characters: http://stackoverflow.com/a/657670
        // special characters that arrive like &0234;
        $str = preg_replace("/&#?[a-z0-9]{2,8};/i", '', $str);

        // remove all leading non numbers
        $str = preg_replace('/^[^0-9]*/', '', $str);

        // remove all thousands separators
        if (strlen($currency->getThousandSeparator())) {
            $str = str_replace($currency->getThousandSeparator(), '', $str);
        }

        if (strlen($currency->getDecimalSeparator())) {
        // make decimal separator regex safe
            $char = preg_quote($currency->getDecimalSeparator());
            // remove all other characters
            $str = preg_replace('/[^'.$char.'\d]/', "", $str);
            // convert all decimal seperators to PHP/bcmath safe decimal '.'
            $str = preg_replace('/'.$char.'/', ".", $str);
        } else {
            // for currencies that do not have decimal points
            // remove all other characters
            $str = preg_replace('/[^\d]/', "", $str);
        }

        return new Money($str, $currency);
    }
363085
public function toCurrencyWords($currency, $decimal, $fraction = null)
    {
        $currency = strtoupper($currency);

        if (!array_key_exists($currency, static::$currencyNames)) {
            throw new NumberToWordsException(
                sprintf('Currency "%s" is not available for "%s" language', $currency, get_class($this))
            );
        }

        $currencyNames = static::$currencyNames[$currency];

        $level = ($decimal == 1) ? 0 : 1;

        if ($level > 0) {
            $currencyNames = self::$currencyNames[$currency];
            if (count($currencyNames[0]) > 1) {
                $ret = $currencyNames[0][$level];
            } else {
                $ret = $currencyNames[0][0] . 's';
            }
        } else {
            $ret = $currencyNames[0][0];
        }

        $ret = $this->wordSeparator . trim($this->toWords($decimal) . ' ' . $ret);

        if (null !== $fraction) {
            $ret .= $this->wordSeparator . 'con' . $this->wordSeparator . trim($this->toWords($fraction));

            $level = ($fraction == 1) ? 0 : 1;

            if ($level > 0) {
                if (count($currencyNames[1]) > 1) {
                    $ret .= $this->wordSeparator . $currencyNames[1][$level];
                } else {
                    $ret .= $this->wordSeparator . $currencyNames[1][0] . 's';
                }
            } else {
                $ret .= $this->wordSeparator . $currencyNames[1][0];
            }
        }

        return $ret;
    }
869132
private void processDefaultCurrency(Integer currencyID) throws SQLException
   {
      List<Row> rows = getRows("select * from " + m_schema + "currtype where curr_id=?", currencyID);
      if (!rows.isEmpty())
      {
         Row row = rows.get(0);
         m_reader.processDefaultCurrency(row);
      }
   }
606360
public static Predicate<MonetaryAmount> isCurrency(
			CurrencyUnit... currencies) {

		if (Objects.isNull(currencies) || currencies.length == 0) {
			return m -> true;
		}
		Predicate<MonetaryAmount> predicate = null;

		for (CurrencyUnit currencyUnit : currencies) {
			if (Objects.isNull(predicate)) {
				predicate = m -> m.getCurrency().equals(currencyUnit);
			} else {
				predicate = predicate.or(m -> m.getCurrency().equals(
						currencyUnit));
			}
		}
		return predicate;
    }
1123837
private void processCurrency(Row row)
   {
      String currencyName = row.getString("curr_short_name");
      DecimalFormatSymbols symbols = new DecimalFormatSymbols();
      symbols.setDecimalSeparator(row.getString("decimal_symbol").charAt(0));
      symbols.setGroupingSeparator(row.getString("digit_group_symbol").charAt(0));
      DecimalFormat nf = new DecimalFormat();
      nf.setDecimalFormatSymbols(symbols);
      nf.applyPattern("#.#");
      m_currencyMap.put(currencyName, nf);

      if (currencyName.equalsIgnoreCase(m_defaultCurrencyName))
      {
         m_numberFormat = nf;
         m_defaultCurrencyData = row;
      }
   }
455011
public TypeSpec createCurrencyUtil(String className, Map<String, CurrencyData> currencies) {
    TypeSpec.Builder type = TypeSpec.classBuilder(className)
        .addModifiers(Modifier.PUBLIC);
    
    CurrencyData defaultData = currencies.get("DEFAULT");
    currencies.remove("DEFAULT");
    
    MethodSpec.Builder code = MethodSpec.methodBuilder("getCurrencyDigits")
        .addModifiers(PUBLIC, STATIC)
        .addParameter(Types.CLDR_CURRENCY_ENUM, "code")
        .returns(int.class);
    
    code.beginControlFlow("switch (code)");
    for (Map.Entry<String, CurrencyData> entry : currencies.entrySet()) {
      CurrencyData data = entry.getValue();
      code.addStatement("case $L: return $L", entry.getKey(), data.digits);
    }
    code.addStatement("default: return $L", defaultData.digits);
    code.endControlFlow();
    
    type.addMethod(code.build());
    return type.build();
  }
746724
public function conversion(float $value = null, string $currency = null, int $transactionId = null): void
	{
		if ($this->config->adWordsConversionId) {
			$data = new ArrayHash;
			$data->value = $value;
			$data->currency = $currency;
			$data->transaction_id = $transactionId ?? '';

			$this->event('conversion',
				'AW-' . $this->config->adWordsConversionId . '/' . $this->config->adWordsConversionLabel,
				$data);
		}
	}
877840
public function convertAndFormat($money, $language = null, $currency = null)
    {
        if (!$currency) {
            $currency = $this->currencyCode;
        }

        $convertedMoney = $money->convertToCurrency($currency);

        return $this->intlFormatter($language)->format($convertedMoney);
    }
1079313
public function setCurrency($currency)
    {
        if ( ! in_array($currency, self::$supportedCurrencies)) {
            throw new CurrencyNotSupported(sprintf('Currency "%s" is not supported.', $currency));
        }
        $this->currency = $currency;
    }
661859
def convert_currency(amount, from_currency, to_currency):
    '''
    

    '''
    try:
        rate = CurrencyRate.objects.get(
            from_currency__iso_code=from_currency,
            to_currency__iso_code=to_currency)
    except CurrencyRate.DoesNotExist:
        return _('n/a')
    try:
        history = rate.history.all()[0]
    except IndexError:
        return _('n/a')
    return amount * history.value
781262
def formatCurrency( value, options = nil )
      value ||= "0.00"
      if !value.include?( '.' )
         value << ".00"
      end
      
      currencySymbol = currencyFormat = nil
      if options
         currencySymbol = options["currencySymbol"]
         currencyFormat = options["currencyFormat"]
      end
      
      if currencySymbol
         if currencyFormat
            if currencyFormat == "0"
               value = "#{currencySymbol}#{value}"
            elsif currencyFormat == "1"
               if value.include?("-")
                  value.gsub!("-","-#{currencySymbol}")
               elsif value.include?("+")
                  value.gsub!("+","+#{currencySymbol}")
               else   
                  value = "#{currencySymbol}#{value}"
               end
            elsif currencyFormat == "2"
               value = "#{value}#{currencySymbol}"
            end
         else
            value = "#{currencySymbol}#{value}"
         end
      end
      
      value
   end
313644
public function convert($currency)
    {
        if ($this->isAvailable($currency)) {
            $rate = 1 / $this->rates[$currency];
            return round($this->base * $rate, 2);
        } else {
            throw new RuntimeException(sprintf(
                'Target currency "%s" does not belong to the registered map of rates', $currency
            ));
        }
    }
961520
public static final CurrencySymbolPosition parseCurrencySymbolPosition(String value)
   {
      CurrencySymbolPosition result = MAP_TO_CURRENCY_SYMBOL_POSITION.get(value);
      result = result == null ? CurrencySymbolPosition.BEFORE_WITH_SPACE : result;
      return result;
   }
298656
public static CurrencyFunction currency(String fieldName, @Nullable String currencyCode) {

		Assert.hasText(fieldName, "FieldName for currency function must not be 'empty'.");
		return currency(new SimpleField(fieldName), currencyCode);
	}