Method Deck / currency

Currency cross rate

Computes the cross exchange rate between two currencies from their two given rates against a common base currency, and converts an amount.

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

Try it

Inputs

Outputs

Steps

  1. Both input rates are quoted the same way: units of that currency per 1 unit of the common base_currency.
  2. The visitor supplies rate_from, rate_to, rate_date, and rate_source together; this method never looks up or fetches a rate itself, so any newer official table may be substituted for all four together.
  3. Compute the cross rate (units of to_currency per 1 unit of from_currency): cross_rate = rate_to / rate_from.
  4. Convert the amount: result = amount * cross_rate.
  5. Round result to 2 decimal places.

Constants

None.

Sources

Worked example and test vectors

NameInputsAnswer
worked example{"amount":10000,"base_currency":"USD","from_currency":"JPY","to_currency":"GBP","rate_from":149.5,"rate_to":0.783,"rate_date":"2026-09-30","rate_source":"Illustrative example rates for cross-rate arithmetic; replace rate_from, rate_to, rate_date, and rate_source with your own dated, cited quotes (for example the ECB euro reference rates page)."}52.37 GBP
test vector: USD/EUR to GBP cross{"amount":100,"base_currency":"EUR","from_currency":"USD","to_currency":"GBP","rate_from":1.1,"rate_to":0.86,"rate_date":"2026-09-30","rate_source":"Illustrative example rates for cross-rate arithmetic; replace rate_from, rate_to, rate_date, and rate_source with your own dated, cited quotes (for example the ECB euro reference rates page)."}78.18 GBP
test vector: identical rates give a 1:1 cross rate{"amount":250,"base_currency":"USD","from_currency":"CAD","to_currency":"AUD","rate_from":1.35,"rate_to":1.35,"rate_date":"2026-09-30","rate_source":"Illustrative example rates for cross-rate arithmetic; replace rate_from, rate_to, rate_date, and rate_source with your own dated, cited quotes (for example the ECB euro reference rates page)."}250.00 AUD

Published card