Data Display

Number Value

A locale-aware number formatter — the four Intl.NumberFormat styles, compact notation, sign control and optional affixes, rendered as tabular figures.

Usage

USD$1,234.56EUR€1,234.56JPY¥1,235GBP£1,234.56

NumberValue is a formatting primitive. It takes one value and renders the string Intl.NumberFormat would produce for it, via @internationalized/number, in a span that carries tabular-nums. The convenience props — style, currency, notation, signDisplay and the fraction-digit pair — are the options you reach for most; formatOptions opens the rest.

It does not animate. Rolling digits belong to headline display values, where the movement is the point; here it would fight the component's job and break the column alignment that tabular figures exist to give you.

Anatomy

Import the NumberValue component and access all parts using dot notation.

import {NumberValue} from "@blakeui/pro-react";

<NumberValue value={0}>
  <NumberValue.Prefix />
  <NumberValue.Suffix />
</NumberValue>;

Both parts are optional and the root renders the formatted value on its own. Order in the markup does not matter — the root picks the prefix and the suffix out of its children and always places them either side of the value.

Compact

1,2341.2K45,67846K1,234,5671.2M9,876,543,2109.9B

Currency

The currency code chooses the symbol and the number of decimals. Yen has no minor unit, so JPY rounds to whole yen while the other three pad to two places.

USD$1,999.90EUR€1,999.90JPY¥2,000GBP£1,999.90

Format Options

formatOptions takes the full Intl.NumberFormatOptions surface plus numberingSystem. It replaces the convenience props rather than merging with them, so anything you still want — style, currency, notation — has to be named inside the object.

Compact currency$1.2MAccounting($1,234.56)

Percent

4.3%87.6%-8.2%

Sign Display

never drops the sign rather than the magnitude, so −42 renders as 42. Use it only where the direction is already carried by something else, such as a colour or an adjacent arrow.

auto420-42always+42+0-42exceptZero+420-42never42042

Tabular Nums

Every root gets font-variant-numeric: tabular-nums from .number-value, so digits occupy equal width and a stacked column lines up on the decimal point. A render-function child is the one way out of it: that form renders your element instead of the root, so add number-value to your own className if the value still needs to align.

$1,234.56$99.99$1,000,000.50$8.75$45,678.90

With Prefix Suffix

228,441revenue1.2Musers$99.99/month

CSS Classes

Base Class

  • .number-value — The root span. Its only declaration is font-variant-numeric: tabular-nums. There is no fill, no stroke, no type scale and no colour: the value inherits its typography from whatever it sits in, which is what lets the same component read as a 12px table cell and a 32px headline without a size prop.

Element Classes

None of the three carries a declaration. They are structural hooks — stable targets for your own stylesheet, and the reason each part is a separate element rather than a text node.

  • .number-value__value — The formatted number. Always present, always the middle child.
  • .number-value__prefix — Text before the value. Rendered only when a NumberValue.Prefix is passed.
  • .number-value__suffix — Text after the value. Rendered only when a NumberValue.Suffix is passed.

Data Attributes

  • [data-slot="number-value"], [data-slot="number-value-value"], [data-slot="number-value-prefix"], [data-slot="number-value-suffix"] — One per part, so any of them can be targeted without depending on its BEM class.

Both sets of hooks are absent under a render-function child, which returns your element in place of the whole tree.

API Reference

NumberValue

The root. Formats value for the resolved locale and renders it in a span.

PropTypeDefaultDescription
valuenumberRequired. The number to format. It is a raw quantity, not a pre-formatted string — under style="percent" it is the ratio, so 0.1432 renders as 14%.
style"decimal" | "currency" | "percent" | "unit""decimal"Which formatting style to use. currency requires currency and unit requires unit; omitting the companion prop throws from Intl rather than falling back. This prop shadows the native style attribute, which the root does not accept — style the element through className.
currencystringISO 4217 code, e.g. "USD". It sets the symbol and the number of decimals — "JPY" has no minor unit and so rounds to whole yen.
unitstringA sanctioned unit identifier, e.g. "celsius", "gigabyte", or a rate such as "megabyte-per-second". Arbitrary strings are not accepted.
notation"standard" | "compact" | "scientific" | "engineering""standard"How the magnitude is written. compact abbreviates using the locale's own scale words; engineering differs from scientific only in snapping the exponent to a multiple of three.
signDisplay"auto" | "always" | "exceptZero" | "never""auto"When to print the sign. exceptZero is the one for deltas; never discards the sign, not the magnitude.
minimumFractionDigitsnumberFewest fraction digits to print, padding with zeros.
maximumFractionDigitsnumberMost fraction digits to print, rounding beyond that. Worth setting under style="percent", whose default of 0 turns a small rate into 1%.
localestringA BCP 47 tag that overrides the locale from the nearest I18nProvider. Left out, the value follows the app's locale — which is normally what you want, and this prop is for the exceptions, such as a figure that must stay in its source locale.
formatOptionsNumberFormatOptionsOptions passed straight through to the formatter: the whole Intl.NumberFormatOptions surface plus numberingSystem. It replaces every convenience prop above rather than merging with them, so re-state anything you still need inside the object.
childrenReactNode | ((formatted: string) => ReactNode)Either NumberValue.Prefix / NumberValue.Suffix parts, or a function receiving the formatted string. The function form renders your element in place of the root, so the class, the data attributes and the tabular figures are yours to reapply.
classNamestringMerged onto .number-value. Ignored under a render-function child, which renders no root.

Also accepts every native span attribute except children and style.

NumberValue.Prefix

Text before the value. A span, rendered inside the root ahead of .number-value__value.

PropTypeDefaultDescription
childrenReactNodeRequired. The affix — a currency code, a comparison operator, a short label. It is content rather than decoration, so it is read out with the number.
classNamestringMerged onto .number-value__prefix. The part carries no styling of its own, so this is where its size, weight, colour and the gap to the value come from.

Also accepts every native span attribute.

NumberValue.Suffix

Text after the value. A span, rendered inside the root behind .number-value__value.

PropTypeDefaultDescription
childrenReactNodeRequired. The affix — a denominator, a unit, a per-period qualifier. Prefer a real unit style where one exists, and keep this for the cases Intl has no identifier for.
classNamestringMerged onto .number-value__suffix. As with the prefix, all of its typography comes from here.

Also accepts every native span attribute.

On this page