Currency
Separators and symbol from Intl. Default 1,234.56 without a symbol; with a code $1,234.56. For Turkish lira use country: "TR". The form value is 1234.56.
← All examples·currency
Preview
Form value: -
Display: -
Details
- Preset:
"currency" - Form value:
"1234.56" - Error keys:
currency.min,currency.max - Kuruş is kept. Both a dot and a comma can be typed as the decimal.
- For math, toMinorUnits returns an integer without float errors.
Customization
Turkish lira
country: "TR" uses the TRY symbol and Turkish separators: ₺1.234,56. The form value is still 1234.56.
Form value: -
Display: -
Following a currency select
Link it to a select with from; the format follows the currency and the form value stays the same.
Form value: 1234.56
Display: ₺1.234,56
Fixed currency, locale and limits
An ISO code, a BCP 47 locale, min and max.
useViraMask(form, {
usd: { preset: "currency", currency: "USD" }, // $1,234.56
euro: { preset: "currency", currency: { code: "EUR", locale: "de-DE" } }, // 1.234,56 €
limit: { preset: "currency", country: "TR", currency: { min: 10, max: 5000 } },
})Amount in minor units
Payment providers (Stripe, Adyen, iyzico) expect the amount as an integer in the smallest unit: 1,234.56 TRY = 123456 kuruş. Doing math with floats gives errors like 0.1 + 0.2 = 0.30000000000000004; toMinorUnits converts the text to an integer exactly.
import { toMinorUnits } from "@virastack/mask"
const price = form.getValues("price") // "1234.56"
toMinorUnits(price, "TRY") // 123456 (kuruş)
toMinorUnits("19.99", "USD") // 1999 (cents)
toMinorUnits("1500", "JPY") // 1500 (yen has no minor unit)For the hook API see useViraMask(); for your own pattern see custom mask.