如何以不同货币显示网站价格?

The site has 5 currencies. The sales price of goods and delivery is set in euros. But the customer can choose the preferred currency to display prices. A better solution would be to keep prices in all currencies in the table "prices" or convert dynamically?

Structure of table "prices":

  • id
  • currency
  • variant_id
  • value
  • original_value

Dynamically. It would be a simple JOIN plus a calculation.

However, ... It would be tempting to ROUND(..,2) when displaying. This works for many Western currencies but does not work well for some of the Gulf states, which need 3 decimal places, or Korea, which does not really use Jeons any more.

If you need to round to a different number of places, use a Stored Function. And/or perhaps the JOIN also gives the number of decimal places.

The answer depend on the business rule. If a price can be calculated by a simple conversion then store only price in some reference currency and convert it dynamically. However, you need a date to store rate history. When a price cannot be calculated dynamically you should store it. The combined approach may be used, too.