---
title: "Recipe: money"
description: "Keep money as a whole number of cents, and format it at the edge with formatNumber(dollars, \"currency\", \"USD\")."
modificationDate: "2026-11-12"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: money

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/money: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

Keep money as a whole number of cents, and format it at the edge with
`formatNumber(dollars, "currency", "USD")`: `$1,481.47`, `-$5.00`, grouped and rounded to
the cent as `Intl.NumberFormat("en-US", {style: "currency", currency: "USD"})` prints it.

```prompt Show money in my app
Make the Exact app in this folder keep and show amounts of money. Use https://github.com/expo/exact/blob/main/docs/recipes/money.md as the source for each step. The Exact checkout has the same page at docs/recipes/money.md.

1. If this folder is not an Exact app (it has no exact.mjs and app.contract), stop and tell me.
2. If I did not say the currency, ask me for its ISO 4217 code (USD, EUR, GBP, JPY) before you write code.
3. Keep every amount as a whole number of cents, in state and in the data the app sends: convert with `round(dollars * 100)` once, where text is parsed. Round each computed amount once, to a cent. Never add amounts as fractions of a dollar.
4. Format only where an amount is shown: write `fn money(cents: number): string = formatNumber(cents / 100, "currency", "<code>")` and use it in each `text`. Use `formatNumber(n, "percent")` for a rate and `formatDecimal(cents, 2)` for a field's value. An amount that changes in place takes `font-variant-numeric="tabular-nums"`.
5. If the person types an amount, follow docs/recipes/number-field.md for the field.
6. Add a test in app.test.contract that expects an amount grouped and rounded to the cent (`$1,748.13`), changes an amount with an action, and expects the new text.
7. Follow the platform checks in docs/start-here.md (`bun exact.mjs docs platform checks`) for the targets in the app's AGENTS.md and app.json until they pass. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 8) and report it; do not keep trying.
8. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
9. Tell me which amounts the app keeps in cents, the currency, what the tests and checks reported, and the launch command for each target platform.
```

```contract
fn money(cents: number): string = formatNumber(cents / 100, "currency", "USD")

component Tip
  state billCents = 148147
  state tipPercent = 18
  derive tipCents = round(billCents * tipPercent / 100)
  action setTip(p: number)
    tipPercent = p
  view
    column padding=16 gap=8
      row justify-content="space-between"
        text "Tip"
        text money(tipCents) font-variant-numeric="tabular-nums" testId="tip"
      row justify-content="space-between"
        text "Total"
        text money(billCents + tipCents) font-variant-numeric="tabular-nums" testId="total"
      row justify-content="space-between"
        text "Tip rate"
        text formatNumber(tipPercent / 100, "percent") testId="rate"
      row role="radiogroup" aria-label="Tip"
        for p in [15, 18, 20] key=p
          button role="radio" aria-checked=(tipPercent == p) press=setTip(p) testId=`tip-${p}` flex=1
            text `${p}%`
```

```contract-test
test "money is grouped and rounded to the cent"
  expect text "tip" == "$266.66"
  expect text "total" == "$1,748.13"
  expect text "rate" == "18%"
  tap "tip-20"
  expect text "total" == "$1,777.76"
```

- Store and send cents (`round(dollars * 100)` once, where the text is parsed): adding
  binary fractions drifts (`0.1 + 0.2`). Round each computed amount once, to a cent.
- `formatNumber(n, "currency", "<code>")` takes an ISO 4217 code literal (USD, EUR, GBP,
  JPY, …; an unknown code is refused at compile time). `formatNumber(n, "decimal")` is a
  grouped number (`1,234.5`), `formatNumber(n, "percent")` a percentage of a fraction
  (`0.256` is `26%`). These are the en-US forms; with a German strings table shown they
  are `1.481,47 $`, `1.234,5` and `26 %`, in the table's locale
  ([formatting by locale](https://exact.expo.dev/reference/contract-grammar/standard-functions-and-intrinsics.md#formatting-by-locale)). A non-finite
  number prints `""`.
- `formatDecimal(cents, 2)` is the exact, ungrouped form (`"1481.47"`) for a field's value.
- Amounts that change in place take `font-variant-numeric="tabular-nums"`.
