# Numeral (/components/typography/numeral)



`Numeral` formats a number with `Intl.NumberFormat`. It reads the active locale from React Aria's
`I18nProvider` and accepts the relevant typography props from `Text`.

apps/docs/src/examples/numeral/basic.tsx

```tsx
import { Numeral } from '@luke-ui/react/numeral';

export default () => {
	return <Numeral value={12_345.67} />;
};
```

## Format [#format]

`Numeral` uses decimal formatting by default. It infers currency or unit formatting when `currency`
or `unit` is present. Set `format` to `'percent'` or `'decimal'` for those formats. Set it to
`'currency'` or `'unit'` when you want that formatting explicit in the component call.

apps/docs/src/examples/numeral/formats.tsx

```tsx
import { Box } from '@luke-ui/react/box';
import { Numeral } from '@luke-ui/react/numeral';
import { Text } from '@luke-ui/react/text';

export default () => {
	return (
		<Box display="flex" flexDirection="column" gap="sp8">
			<Text>
				Conversion rate: <Numeral format="percent" value={0.125} />
			</Text>
			<Text>
				Ticket price: <Numeral currency="AUD" value={98.76} />
			</Text>
			<Text>
				Wind speed: <Numeral unit="kilometer-per-hour" value={98} />
			</Text>
			<Text>
				Page views: <Numeral format="decimal" value={12_345} />
			</Text>
		</Box>
	);
};
```

## Compact notation [#compact-notation]

Set `abbreviate` for compact notation such as `12K`. Pass `"long"` for a long display such as
`12 thousand`.

apps/docs/src/examples/numeral/compact.tsx

```tsx
import { Box } from '@luke-ui/react/box';
import { Numeral } from '@luke-ui/react/numeral';
import { Text } from '@luke-ui/react/text';

export default () => {
	return (
		<Box display="flex" flexDirection="column" gap="sp8">
			<Text>
				Short: <Numeral abbreviate value={12_345} />
			</Text>
			<Text>
				Long: <Numeral abbreviate="long" value={12_345} />
			</Text>
		</Box>
	);
};
```

## Precision [#precision]

Pass a number for fixed fraction digits or a `[min, max]` tuple for a range. Use `formatOptions` for
other `Intl.NumberFormat` options.

apps/docs/src/examples/numeral/precision.tsx

```tsx
import { Box } from '@luke-ui/react/box';
import { Numeral } from '@luke-ui/react/numeral';
import { Text } from '@luke-ui/react/text';

export default () => {
	return (
		<Box display="flex" flexDirection="column" gap="sp8">
			<Text>
				Fixed: <Numeral precision={2} value={98.7654} />
			</Text>
			<Text>
				Range: <Numeral precision={[0, 2]} value={1_234.5678} />
			</Text>
		</Box>
	);
};
```

## Formatting rules [#formatting-rules]

`Numeral` throws when:

* you provide both `currency` and `unit`.
* you use `format="currency"` without a `currency` code.
* you use `format="unit"` without a `unit` value.
* `precision` is not a non-negative integer or a valid `[min, max]` tuple.

## Typography and alignment [#typography-and-alignment]

Numerals use tabular figures and end alignment by default, so values remain readable in a column.
Set `fontVariantNumeric`, `textAlign`, or inherited `Text` typography props when the context needs a
different treatment.

## Related components [#related-components]

Use [Text](/components/typography/text) for non-numeric content and
[Heading](/components/typography/heading) for section titles.

## API [#api]

<ComponentPropsTable
  id="type-table-numeral.tsx-NumeralProps"
  type="{
  &#x22;id&#x22;: &#x22;numeral.tsx-NumeralProps&#x22;,
  &#x22;name&#x22;: &#x22;NumeralProps&#x22;,
  &#x22;description&#x22;: &#x22;Props for `Numeral`.&#x22;,
  &#x22;entries&#x22;: [
    {
      &#x22;name&#x22;: &#x22;abbreviate&#x22;,
      &#x22;description&#x22;: &#x22;Enables compact notation (`1.2K`, `1.2 thousand`).&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;NumeralAbbreviation | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;currency&#x22;,
      &#x22;description&#x22;: &#x22;Currency code such as `USD`.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;string | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;string&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;fontVariantNumeric&#x22;,
      &#x22;description&#x22;: &#x22;Numeric glyph rendering mode.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'tabular-nums'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;normal\&#x22; | \&#x22;default\&#x22; | \&#x22;diagonal-fractions\&#x22; | \&#x22;ordinal\&#x22; | \&#x22;slashed-zero\&#x22; | \&#x22;tabular-nums\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;format&#x22;,
      &#x22;description&#x22;: &#x22;Number format style. Inferred from `currency`/`unit` when omitted.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;NumeralFormat | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;formatOptions&#x22;,
      &#x22;description&#x22;: &#x22;Extra options passed to `Intl.NumberFormat`.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;Intl.NumberFormatOptions | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;object&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;locale&#x22;,
      &#x22;description&#x22;: &#x22;Locale used for formatting. Defaults to locale context.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;Intl.LocalesArgument&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;LocalesArgument&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;precision&#x22;,
      &#x22;description&#x22;: &#x22;Precision as fixed digits or `[min, max]` digits.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;NumeralPrecision | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;textAlign&#x22;,
      &#x22;description&#x22;: &#x22;Text alignment. Right-aligned by default for numeric columns.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'end'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;center\&#x22; | \&#x22;end\&#x22; | \&#x22;start\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;unit&#x22;,
      &#x22;description&#x22;: &#x22;Unit name when `format` is `unit`, e.g. `kilometer`.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;string | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;string&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;value&#x22;,
      &#x22;description&#x22;: &#x22;Number to format.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;number&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;number&#x22;,
      &#x22;required&#x22;: true,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;color&#x22;,
      &#x22;description&#x22;: &#x22;Sets text colour.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'primary'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;accent\&#x22; | \&#x22;info\&#x22; | \&#x22;success\&#x22; | \&#x22;warning\&#x22; | \&#x22;danger\&#x22; | \&#x22;primary\&#x22; | \&#x22;secondary\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;elementType&#x22;,
      &#x22;description&#x22;: &#x22;Renders a different element type in place of the default. Use it to choose a semantic element\nwithout changing the visual or accessibility treatment.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;string | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;string&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;render&#x22;,
      &#x22;description&#x22;: &#x22;Overrides the default DOM element with a custom render function.\nThis allows rendering existing components with built-in styles and behaviors\nsuch as router links, animation libraries, and pre-styled components.\n\nRequirements:\n\n- You must render the expected element type (e.g. if `<button>` is expected, you cannot render an\n  `<a>`).\n- Only a single root DOM element can be rendered (no fragments).\n- You must pass through props and ref to the underlying DOM element, merging with your own prop\n  as appropriate.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;DOMRenderFunction<any, any> | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;DOMRenderFunction<any, any>&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;fontStyle&#x22;,
      &#x22;description&#x22;: &#x22;Sets font style.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'default'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;normal\&#x22; | \&#x22;inherit\&#x22; | \&#x22;default\&#x22; | \&#x22;italic\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;fontWeight&#x22;,
      &#x22;description&#x22;: &#x22;Sets the semantic font-weight role. When omitted, the selected typography style supplies its\nweight.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;\&#x22;label\&#x22; | \&#x22;body\&#x22; | \&#x22;heading\&#x22; | \&#x22;emphasis\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;isVisuallyHidden&#x22;,
      &#x22;description&#x22;: &#x22;Hides text visually while keeping it accessible.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;false&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;boolean | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;lineClamp&#x22;,
      &#x22;description&#x22;: &#x22;Clamps text lines. `true` clamps to 1 line; numeric values clamp to 1–5.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;boolean | 2 | 1 | 3 | 4 | 5 | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;shouldDisableTrim&#x22;,
      &#x22;description&#x22;: &#x22;Turns cap-height trim on or off. When omitted, trimming is disabled for inline or unknown\nelement types. Line clamp always disables trim.&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;boolean | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;shouldInheritFont&#x22;,
      &#x22;description&#x22;: &#x22;Makes text inherit its surrounding font and colour styles.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;false&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;boolean | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;textDecoration&#x22;,
      &#x22;description&#x22;: &#x22;Sets text decoration.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'none'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;none\&#x22; | \&#x22;inherit\&#x22; | \&#x22;line-through\&#x22; | \&#x22;underline\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;textTransform&#x22;,
      &#x22;description&#x22;: &#x22;Sets text transform.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'none'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;none\&#x22; | \&#x22;inherit\&#x22; | \&#x22;default\&#x22; | \&#x22;capitalize\&#x22; | \&#x22;lowercase\&#x22; | \&#x22;uppercase\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;textWrap&#x22;,
      &#x22;description&#x22;: &#x22;Sets text wrapping behavior.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'default'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;balance\&#x22; | \&#x22;default\&#x22; | \&#x22;pretty\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;name&#x22;: &#x22;typography&#x22;,
      &#x22;description&#x22;: &#x22;Applies a complete typography style: family, size, weight, line height, letter spacing, and\ntrim.&#x22;,
      &#x22;tags&#x22;: [
        {
          &#x22;name&#x22;: &#x22;default&#x22;,
          &#x22;text&#x22;: &#x22;'body'&#x22;
        }
      ],
      &#x22;type&#x22;: &#x22;\&#x22;caption\&#x22; | \&#x22;label\&#x22; | \&#x22;body\&#x22; | \&#x22;lead\&#x22; | \&#x22;heading4\&#x22; | \&#x22;heading3\&#x22; | \&#x22;heading2\&#x22; | \&#x22;heading1\&#x22; | \&#x22;display\&#x22; | undefined&#x22;,
      &#x22;simplifiedType&#x22;: &#x22;union&#x22;,
      &#x22;required&#x22;: false,
      &#x22;deprecated&#x22;: false
    },
    {
      &#x22;deprecated&#x22;: false,
      &#x22;description&#x22;: &#x22;`NumeralProps` also accepts compatible DOM and ARIA attributes and event handlers for its rendered element.&#x22;,
      &#x22;name&#x22;: &#x22;__nativePropsForwarding&#x22;,
      &#x22;required&#x22;: true,
      &#x22;simplifiedType&#x22;: &#x22;&#x22;,
      &#x22;tags&#x22;: [],
      &#x22;type&#x22;: &#x22;&#x22;
    }
  ]
}"
/>
