Price

Price

HkPrice is the money-display atom: a currency code's minor-unit digits (or an explicit precision), an optional unit suffix such as /1M, an optional reference conversion, and tabular-nums so a column of figures aligns digit-for-digit. It never guesses: an unfilled amount is a calm em dash with a "Not set" accessible name, and a reference conversion renders only when its rate is a finite number above zero.

  • For a value that animates while the user watches, use HkRollingNumber; the price is a still figure.
  • For an editable amount, the field is HkMoneyInput's job, not this component's: HkPrice has no input, no focus target and no model.
  • A proportion of a total ("8,231 of 20,000") is HkShareBar's job; a price is one amount, not a ratio.

Import

TSX
USD42.00

currency is a plain object — { code, symbol?, name?, decimals } — not a code string: the minor-unit digit count is what decides the default precision, so a host that already holds a settings row passes it as is. normalizeCurrency trims and upper-cases the code, forces decimals into 0..8 and drops an empty symbol, so a half-filled row renders instead of throwing.

Amounts and precision

amount is in currency's major units and is formatted with the currency's minor-unit digits unless precision overrides them (clamped to 0..8). Grouping is , every three integer digits and the decimal separator is . in every locale, so the displayed text round-trips through a parser and can never be read as a different number. unit is a plain suffix rendered after the amount.

The symbol is decorative (aria-hidden): the spoken name is the currency code, because a bare $ is ambiguous between USD, CAD and AUD.

TSX
USD1,234.50JPY1,235KWD1,234.500USD0.000420/1M

An unset amount

null, undefined and non-finite amounts were never a price of zero: they render an em dash with the accessible name "Not set", in quiet ink. A zero amount is a real amount and renders 0.00.

TSX
Not setUSD0.00

Reference conversion

reference is { currency, rate, asOf? }, where rate is how many reference units one primary unit buys and asOf is an opaque host-formatted timestamp the component never parses. The conversion renders as a secondary "≈" figure only when the rate is a finite number above zero; a missing, zero, negative or NaN rate renders the primary amount alone, because an amount is never converted by a guessed rate. The audit line — "Approximate · 1 USD = 0.92 EUR · As of <date>" — is both the tooltip and the native title, so the figure stays auditable without hover.

The reference span is focusable (tabindex=0) so the tooltip opens from the keyboard as well as from the pointer.

TSX
USD42.00ApproximateEUR38.64USD42.00

Shape and size

variant picks the skeleton: text (the default) for prose and detail rows, chip for a pill in a dense table; size is md (the default) or sm. Both keep the figures tabular and only the surrounding type scales.

TSX
USD12.50USD12.50

API

Vue

Props

NameTypeDefaultRequired
amount<code>Number as PropType<number | null | undefined></code>undefined—
currencyObject as PropType<HkCurrency>—✓
precisionNumberundefined—
unitStringundefined—
reference<code>Object as PropType<HkPriceReference | null></code>null—
variant<code>String as PropType<"text" | "chip"></code>"text"—
size<code>String as PropType<"sm" | "md"></code>"md"—

Accessibility

  • The symbol is decorative (aria-hidden="true"); the currency code is rendered as visually hidden text inside the primary span, so the spoken reading is "USD 1,234.50" rather than an ambiguous "$1,234.50".
  • An unset amount announces "Not set" from a visually hidden span; the em dash itself is aria-hidden.
  • The reference figure is prefixed by a visually hidden "Approximate" and followed by the reference code; the conversion's evidence (rate and as-of stamp) is the title and the tooltip text, so it is reachable by hover, by focus and by copy.
  • The reference span is a tabindex="0" stop with a focus-visible outline; a static amount adds no stop of its own.
  • Digits are tabular-nums, so a column does not shift when the values change.

Related components

  • HkRollingNumber — a figure that rolls when it changes, for live readouts.
  • HkShareBar — the proportion bar for an "X of Y" breakdown.
  • HkCopyBadge — the interactive tag, when the figure is an identifier that should be copied.
  • Comment — the comment block, when a price is part of a threaded note.
  • HkTag — the static label pill, when the text is a category rather than a figure.