FormattedNumber
Formats a number, amount, percentage, or measurement with Intl.NumberFormat and keeps the raw value machine-readable.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add FormattedNumber- Interaction
- Native markup
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View FormattedNumber code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import { FormattedNumber, Stack } from '@santi020k/lumen-astro'
---
<Stack gap="xs">
<FormattedNumber value={1234.5} format="currency" currency="USD" locale="en-US" />
<FormattedNumber value={1234.5} format="currency" currency="EUR" locale="de-DE" />
<FormattedNumber value={0.256} format="percent" locale="en-US" maximumFractionDigits={1} />
<FormattedNumber value={1250000} notation="compact" locale="en-US" />
<FormattedNumber value={512} format="unit" unit="megabyte" locale="en-US" />
<FormattedNumber value={12} signDisplay="always" locale="en-US" />
</Stack>import { FormattedNumber, Stack } from '@santi020k/lumen-react'
export const Example = () => (
<>
<Stack gap="xs">
<FormattedNumber value={1234.5} format="currency" currency="USD" locale="en-US" />
<FormattedNumber value={1234.5} format="currency" currency="EUR" locale="de-DE" />
<FormattedNumber value={0.256} format="percent" locale="en-US" maximumFractionDigits={1} />
<FormattedNumber value={1250000} notation="compact" locale="en-US" />
<FormattedNumber value={512} format="unit" unit="megabyte" locale="en-US" />
<FormattedNumber value={12} signDisplay="always" locale="en-US" />
</Stack>
</>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-stack gap="xs">
<lumen-formatted-number value="1234.5" format="currency" currency="USD" locale="en-US"></lumen-formatted-number>
<lumen-formatted-number value="1234.5" format="currency" currency="EUR" locale="de-DE"></lumen-formatted-number>
<lumen-formatted-number value="0.256" format="percent" locale="en-US" maximum-fraction-digits="1"></lumen-formatted-number>
<lumen-formatted-number value="1250000" notation="compact" locale="en-US"></lumen-formatted-number>
<lumen-formatted-number value="512" format="unit" unit="megabyte" locale="en-US"></lumen-formatted-number>
<lumen-formatted-number value="12" sign-display="always" locale="en-US"></lumen-formatted-number>
</lumen-stack>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
rsx! {
FormattedNumber {
value: 1234,
format: FormattedNumberFormat::Currency,
currency: "USD",
notation: FormattedNumberNotation::Compact,
}
}
}Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add FormattedNumberpnpm add @santi020k/lumen-reactlumen add FormattedNumber --target reactpnpm add @santi020k/lumen-elementslumen add FormattedNumber --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| value | number | numeric string | required | The number. It becomes the value attribute of the rendered data element. Anything that is not a finite number renders the fallback. |
| format | "decimal" | "currency" | "percent" | "unit" | "decimal" | The Intl.NumberFormat style. Named format because style is the CSS attribute. Percent expects a ratio, so 0.25 shows 25%. |
| locale | BCP 47 string | "en" | Formats for this locale. Invalid or unsupported tags fall back to en, so server and client output match. |
| currency | ISO 4217 code | - | Required for the currency format; without a valid three-letter code the number renders as a decimal. |
| currencyDisplay | "symbol" | "narrowSymbol" | "code" | "name" | "symbol" | How the visible text shows the currency. |
| currencyName | "auto" | "always" | "never" | "auto" | When to read the full currency name to assistive technology. auto names symbols that several currencies share, such as $, ¥, £, and kr. |
| unit, unitDisplay | Intl unit, "short" | "narrow" | "long" | -, "short" | Required for the unit format, such as kilobyte. Unknown units render a plain decimal. |
| notation | "standard" | "scientific" | "engineering" | "compact" | "standard" | Compact shows 1.3M and reads "1.3 million" to assistive technology. |
| signDisplay | "auto" | "always" | "exceptZero" | "never" | "auto" | Controls the plus and minus signs, for example always for deltas. |
| minimumFractionDigits, maximumFractionDigits | number | Intl default | Clamped to 0-20. A maximum below the minimum is raised to the minimum. |
| fallback | string | "—" | Text shown for invalid input. The root becomes a span with data-invalid. |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize FormattedNumber
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-formatted-number {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-formatted-number through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
| Hook | Values | Default | Contract |
|---|---|---|---|
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope