Skip to main content
Urbicon UI
source

CurrencyInput

Locale-aware monetary input that stores values in minor units (cents). Raw editing on focus, formatted display with currency symbol on blur.

Playground

Locale
Currency
Symbol Position
<CurrencyInput
  label="Price"
  locale="de-DE"
/>

01 Examples

Default — follows the active i18n locale

Cents are stored as integers; the € symbol is a static adornment. Grouping and decimal separators follow the active i18n locale (this site runs 'en', so 1,234.56), applied on blur — no explicit locale prop needed.
<script>
  let priceCents = $state(1234_56); // grouped per the active locale
</script>
<CurrencyInput label="Price" bind:value={priceCents} />

USD with prefix symbol

<CurrencyInput
  label="Amount"
  bind:value={amountCents}
  locale="en-US"
  currency="USD"
  symbolPosition="prefix"
/>

JPY — zero decimal precision

Currencies like JPY have no minor units. Set precision=0 so the integer value is treated as-is.
<CurrencyInput
  bind:value={yen}
  locale="ja-JP"
  currency="JPY"
  precision={0}
/>

02 Working with major units

CurrencyInput stores values in minor units (cents) so summing, sorting, and persisting amounts stay free of floating-point drift. When integrating with an API or datastore that uses major-unit floats (e.g. 1234.56 for €1.234,56), use the exported centsToMajor / majorToCents helpers at the boundary — and keep the in-memory representation in cents.

Cents in, major units out

majorToCents on ingest, centsToMajor on export. The bound value stays in cents.

Stored as cents: 123456 · Exported as major: 1234.56

<script>
  import { CurrencyInput, centsToMajor, majorToCents } from '@urbicon-ui/blocks';

  // Major-unit float arrives from an external API.
  const apiAmount = 1234.56;
  let cents = $state(majorToCents(apiAmount)); // 123456
  const exportedAsMajor = $derived(centsToMajor(cents)); // 1234.56
</script>

<CurrencyInput label="Price" bind:value={cents} />
<p>Major: {exportedAsMajor}</p>

Float-precision caveat: a major-unit value that has already lost precision before reaching majorToCents (e.g. 0.1 + 0.2) cannot be recovered. For values that must round-trip exactly across system boundaries, transport them as minor-unit integers (or as strings) instead of major-unit floats.

03 Customization

CurrencyInput wraps <Input>, so all InputProps (label, helper, error, slotClasses, …) flow through. The cents-based value, locale, currency, symbolPosition, and precision props add the locale-aware behaviour on top.

Use symbolPosition="none" for headless numeric editing where you want the locale formatting (grouping / decimal separator) without the currency symbol.

04 Accessibility

Inherited from Input

Inherits aria-invalid / aria-describedby wiring from the underlying <Input> via the label, error, and helper props.

Numeric keyboard

Sets inputmode="decimal" so mobile keyboards open the numeric pad with a decimal separator.

Raw value while focused

Raw editing while focused — formatting happens on blur, so screen-reader users hear the unambiguous typed value.

05 API Reference

33 props
32 props
Prop
Type
Default
Description

06 Types

Local type definitions used by this component.

10 types
Name
Kind
Category
Used by
Description

07 Installation

Import

import { CurrencyInput } from '@urbicon-ui/blocks';