Method Deck / currency

Currency conversion at a stated reference rate.

Converts an amount between EUR and one other currency using a stated rate (units of that currency per 1 EUR), the date it applies to, and its cited source, all supplied by the visitor.

Published for review. The Founder is checking every card himself; anything he strikes comes down the same hour.

Try it

Inputs

Outputs

Steps

  1. Exactly one of from_currency and to_currency must be EUR (or both are EUR); for two non-EUR currencies use the currency-cross-rate card instead.
  2. The visitor supplies rate (units of the non-EUR currency per 1 EUR), rate_date (the date that rate applies to), and rate_source (the citation it came from); this method never looks up or fetches a rate itself, so any newer official table may be substituted for all three together.
  3. If from_currency is EUR: result = amount * rate (EUR converted into the foreign currency).
  4. If to_currency is EUR: result = amount / rate (the foreign currency converted into EUR).
  5. If from_currency equals to_currency: result = amount unchanged, regardless of rate.
  6. Round result to 2 decimal places.

Constants

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"amount":100,"from_currency":"USD","to_currency":"EUR","rate":1.1355,"rate_date":"2026-09-30","rate_source":"https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html"}88.07 EUR
test vector: EUR to JPY{"amount":100,"from_currency":"EUR","to_currency":"JPY","rate":178.27,"rate_date":"2026-09-30","rate_source":"https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html"}17,827.00 JPY
test vector: CAD to EUR{"amount":200,"from_currency":"CAD","to_currency":"EUR","rate":1.6105,"rate_date":"2026-09-30","rate_source":"https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html"}124.19 EUR

Published card