Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
IntegrationsNovember 22, 20265 min read

Currencies and Exchange Rates

Money looks like a number until you add a second currency. Here is how to store it, format it, convert it with live rates, and avoid the rounding bugs that show up in totals.

Startbase Team
Editorial ink illustration of a brass balance scale with stacked coins on each pan and a paper rate card propped at its base, the rate card in ember orange

Key takeaways

  • Store every amount as an integer in the currency's smallest unit plus its three-letter code. Never store money as a floating-point number.
  • Fetch exchange rates on a schedule into your own table, and keep the rate used on every order so history never changes.
  • Converted prices are estimates unless you charge in that currency; label them, and show when the rate was last updated.

To handle currencies in an app, store each amount as a whole number in the currency's smallest unit (1999 cents, not 19.99 dollars) next to its ISO 4217 code (USD, EUR, JPY), format it for display with the browser's built-in Intl.NumberFormat, and get exchange rates from a rates source on a schedule rather than on every page view. Free and paid sources include the European Central Bank's daily reference rates, Frankfurter (a free API built on that data) and Open Exchange Rates (an account and app ID, with free and paid plans). Cache rates in your database, and record the exact rate used whenever a conversion affects money that changes hands.

What you will build

Three pieces that most multi-currency apps need: a money model that cannot drift, a price display that looks right in every locale ("$1,299.00", "1.299,00 €", "¥1,299"), and a conversion layer for things like an expense splitter that mixes currencies from a trip, a marketplace showing approximate prices to foreign visitors, a travel budget, or a dashboard totaling sales from several countries.

Storing money so it never drifts

Floating-point numbers cannot represent most decimal fractions exactly. In JavaScript, 0.1 + 0.2 is 0.30000000000000004, and those tiny errors compound across a cart or a year of sales. The fix is boring and universal:

  • amount_minor: an integer (bigint in Postgres) in the smallest unit. 19.99 USD is 1999.
  • currency: the three-letter ISO code, in a separate column, on every row that holds an amount. An amount without a currency is a bug waiting for a second market.
  • Know the exponent. Most currencies have 2 decimal places, but JPY and KRW have 0, and KWD, BHD and OMR have 3. Keep a small currencies table (code, exponent, symbol) or use Intl's data, and never assume divide by 100.
  • Do math in integers. Add and subtract minor units. When you must multiply (tax, discounts, conversion), use a decimal library or integer math and round once, at a defined step.

Pick one rounding rule and apply it everywhere: round half up is what most people expect on receipts; round half to even (banker's rounding) reduces bias over many operations and is common in accounting. Round per line or per total, consistently, and your invoices will always add up. The database basics guide covers column types if bigint versus numeric is new to you.

Formatting for people

Intl.NumberFormat with style "currency" and the currency code does the hard part: symbol placement, separators and decimals per locale. new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }) formats 1299 euros as "1.299,00 €"; the same amount in "en-US" shows "€1,299.00". Format from the user's locale, not their currency: an American looking at a euro price still expects American separators. When symbols are ambiguous ($ means many currencies), show the code too: "US$12" or "12 USD".

Input is the mirror problem. A German user typing "12,50" means twelve and a half, and an American typing "1,250" means one thousand two hundred fifty. Parse amounts with the user's locale in mind (or use a currency input that formats as they type), convert to minor units immediately, and show the parsed value back before saving. Reject more decimal places than the currency allows rather than silently rounding: 3.999 dollars is a typo, not a price. For a currency picker, list the user's likely currencies first (their locale's currency and the ones they used before), then the rest alphabetically by code.

What you need for live rates

  • A rates source. The European Central Bank publishes euro reference rates for around 30 currencies once per working day; Frankfurter serves the same data as a free API with no key. Commercial APIs such as Open Exchange Rates cover more currencies and update more often; they need an account and an app ID or key, and free plans often limit the base currency and update frequency.
  • Somewhere to keep the key. If your source needs one, it goes in Secrets, for example as FX_API_KEY, read only by an edge function.
  • A schedule. A database job. Daily is enough for display; hourly if your plan allows and your use needs it. Reference rates only change once a day, so polling them hourly only costs calls.

The data flow

  1. 01A job runs at a fixed time (for ECB-based data, after the daily publication in the European afternoon) and calls a fetch-rates function.
  2. 02The function fetches all rates against one base currency and writes rows to fx_rates: base, quote, rate (numeric, not float), as_of date, source.
  3. 03Your app reads the latest rates from that table. Cross rates come from the base: GBP to JPY is (EUR to JPY) divided by (EUR to GBP).
  4. 04Display conversions are computed on the fly and labeled: "≈ $54.20, rate as of 21 Nov".
  5. 05Any conversion that becomes money (a settlement, a refund, an expense split that people will pay) stores the rate, its as_of date and the converted amount on the row. Next month's rate must never change last month's balances.

A brief you can paste

Make the trip expense splitter multi-currency. Store every amount as amount_minor (bigint) plus a currency code, with a currencies table holding each code's decimal places (JPY 0, KWD 3, most 2). Each trip has a home currency. Add an fx_rates table (base, quote, rate as numeric, as_of, source) filled daily by a scheduled edge function that fetches euro reference rates; compute cross rates from the euro base. When someone adds an expense in another currency, convert it to the home currency with the latest rate, round half up once, and store the rate, its date and the converted amount on the expense so balances never shift. Format all money with Intl.NumberFormat in the viewer's locale, show the currency code when the symbol is ambiguous, and show converted figures as approximate with the rate date.

Pitfalls

  • Promising a converted price. If you show "≈ €46" but charge 50 US dollars, the customer's bank converts at its own rate, plus fees. Label conversions as estimates, or price natively in each currency you sell in. Your payment provider's settings decide which currencies you actually charge; see accept payments in your app.
  • Reference rates are not trading rates. ECB rates are for information. They are fine for display and splitting a dinner, not for quoting a binding exchange.
  • Weekends and holidays. Reference sources do not publish then. Use the latest available rate and show its date rather than failing.
  • Storing rates as floats. Use numeric columns and a decimal library for conversion math, for the same reasons as amounts.
  • Summing mixed currencies. A dashboard total of 100 USD plus 100 EUR is not 200 of anything. Convert each to a reporting currency first, at a stated rate and date.
  • Hard-coding symbols. "$" before every number breaks for most of the world. Let Intl format, and test with at least one zero-decimal currency like JPY.

Frequently asked questions

How should I store money in a database?

As an integer in the currency's smallest unit, such as cents, with the three-letter currency code in a separate column. Avoid floating-point types, which introduce rounding errors.

Is there a free exchange rate API?

Yes. The European Central Bank publishes free daily reference rates, and Frankfurter serves that data as an API with no key. Commercial providers offer more currencies and more frequent updates, usually with free and paid plans.

How often should I update exchange rates?

Daily is enough for displaying approximate prices and splitting expenses. Reference rates change once per working day, so update more often only if your source and use case truly need it.

How do I format currency for different countries?

Use Intl.NumberFormat with style set to currency and the currency code, and pass the viewer's locale. It handles symbols, separators and decimal places for you.

On this page

  • What you will build
  • Storing money so it never drifts
  • Formatting for people
  • What you need for live rates
  • The data flow
  • A brief you can paste
  • Pitfalls

Keep reading

More in Integrations
Editorial ink illustration of a folded paper street map with a brass compass and pushpins, the center pushpin in ember orange
IntegrationsNovember 22, 2026

How to add a map to your app

A map is two jobs: drawing tiles in the browser and turning addresses into coordinates. One key can be public, the other never should be.

6 min read
Editorial ink illustration of a carrier pigeon on a windowsill with a rolled note tied to its leg, the note in ember orange
IntegrationsNovember 22, 2026

How to send SMS from your app

Sending one text is ten lines of code. Sending texts people agreed to, that arrive, and that nobody can abuse, is the real work.

5 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.