---
title: "Recipe: a number field"
description: "inputmode=\"decimal\" is the iPhone's number pad with a decimal point, \"numeric\" digits only; without one, the full keyboard."
modificationDate: "2026-11-30"
---

> ## 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: a number field

<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/number-field: <what was wrong or missing>"`

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

</AgentInstructions>

`inputmode="decimal"` is the iPhone's number pad with a decimal point, `"numeric"` digits only;
without one, the full keyboard. `type="number"` gets the number pad when its `step` and `min`
are whole or unsaid (else the decimal pad), and the platform's stepper, which adds `step`: for a
count, or a value in a unit (`step=50` ml). A typed amount is `inputmode` alone, as `Bill` is.
The field holds raw text; a derive parses it.

```prompt Add a number field
Add a number field to the Exact app in this folder. Use https://github.com/expo/exact/blob/main/docs/recipes/number-field.md as the source for each step. The Exact checkout has the same page at docs/recipes/number-field.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 what the field holds, ask me before you write code: a count, an amount of money, or a value in a unit, and whether it can be negative.
3. In app.contract, keep the field's raw text in a `string` state and parse it in a derive with `parseNumber`. Pick the keyboard from the recipe: `inputmode="decimal"` for an amount, `inputmode="numeric"` for digits only, or `type="number"` with a `step` for a count or a value in a unit. Never `inputmode="text"` for a number. A value that can be negative says its range with `min`.
4. `input` writes the raw text at each keystroke; normalize the text only in `change` (Enter or blur), never as the person types. When the text does not parse, say so in words (a footer), set `aria-invalid`, and leave the text as typed; do not paint it red. In a form that saves, put `submit=save` on the field and keep Save disabled until the text is valid. For money, also follow docs/recipes/money.md.
5. Add a test in app.test.contract that types text that does not parse and expects the message, then types a valid value and expects the result. For a value committed on Enter, type it, then `type "<id>" key "Enter"`, and expect the committed value.
6. 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 7) and report it; do not keep trying.
7. 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.
8. Tell me the field, its keyboard, the rule for valid text, what the tests and checks reported, and the launch command for each target platform.
```

```contract
fn amount(s: string): number = match parseNumber(s) { case some(n) => n, case none => -1 }

component Split
  state billText = ""
  state people = 2
  state peopleText = "2"
  derive bill = amount(billText)
  derive billError = billText != "" and bill < 0 ? "Enter an amount, like 42.50." : ""
  action editBill(v: string)
    billText = v
  action editPeople(v: string)
    peopleText = v
  action commitPeople(v: string)
    let n = round(amount(v))
    let next = n >= 1 ? n : people
    people = next
    peopleText = `${next}`
  view
    list appearance="auto" listStyle="inset-grouped" height="100%" testId="app"
      section
        row
          text "Bill"
          input value=billText input=editBill inputmode="decimal" placeholder="0.00" aria-label="Bill"
            aria-invalid=(billError != "") text-align="end" testId="bill" flex=1 min-width=0
        row
          text "People"
          input value=peopleText input=editPeople change=commitPeople inputmode="numeric"
            aria-label="People" text-align="end" testId="people" flex=1 min-width=0
        footer
          text billError testId="bill-error"
      section
        row
          text "Each Pays"
          text (bill > 0 ? (bill / people).toFixed(2) : "—") font-variant-numeric="tabular-nums" testId="share"
```

```contract-test
test "a bad amount says so, and people commit on Enter"
  type "bill" "12.5.0"
  expect text "bill-error" == "Enter an amount, like 42.50."
  type "bill" "84"
  expect text "share" == "42.00"
  type "people" "0"
  type "people" key "Enter"
  expect text "people" == "2"
  type "people" "3"
  type "people" key "Enter"
  expect text "share" == "28.00"
```

- `input` writes the raw text at each keystroke; normalize this number in `change` (Enter or blur)
  so a leading minus or trailing decimal point survives while typing. `parseNumber` answers `none` for `""`, `"12px"`: say so in words (the footer, not red:
  red is a refusal the data sent back) and leave the text as typed.
- The number pad has no Return key: iOS gives it a Done bar that puts it away and fires
  `change`.
- A value that can be negative: the decimal pad has no minus key, so say the range: `min=-273.15`
  (bare) gives iOS a ± key in the keyboard's bar. Never `inputmode="text"` for a number.
- In a form that saves: `submit=save` on the field (Enter saves; no `form`), `aria-invalid`
  while the text is bad, Save disabled until valid, saying why ([grouped form](https://exact.expo.dev/recipes/grouped-form.md)). Money: [money](https://exact.expo.dev/recipes/money.md); a big result: [numeric readout](https://exact.expo.dev/recipes/numeric-readout.md).
