importCurrencyInputfrom'solid-currency-input-field'
;<CurrencyInputid="input-example"name="input-name"placeholder="Please enter a number"defaultValue={1000}decimalsLimit={2}onValueChange={(value,name) => console.log(value, name)}
/>
Have a look in src/examples for more examples on implementing and validation.
currency should be a ISO 4217 currency code, such as "USD" for the US dollar, "EUR" for the euro, or "CNY" for the Chinese RMB.
Any prefix, suffix, group separator and decimal separator options passed in will override the default locale settings.
Decimal Scale and Decimals Limit
decimalsLimit and decimalScale sound similar but have different usages.
decimalsLimit prevents the user from typing more than the limit, and decimalScale will format the decimals onBlur to the specified length, padding or trimming as necessary.
Example:
If decimalScale is 2
- 1.5 becomes 1.50 (padded)
- 1.234 becomes 1.23 (trimmed)
---
If decimalLimit is 2
- User enters 1.23
- User is then prevented from entering another value
Fixed Decimal Length
Use fixedDecimalLength so that the value will always have the specified length of decimals.
Use the formatValue function to format the values to a more user friendly string. This is useful if you are displaying the value somewhere else ie. the total of multiple inputs.
import { formatValue } from'solid-currency-input-field'// Format using prefix, groupSeparator and decimalSeparatorconst formattedValue1 = formatValue({
value: '123456',
groupSeparator: ',',
decimalSeparator: '.',
prefix: '$',
})
console.log(formattedValue1)
// $123,456// Format using intl locale configconst formattedValue2 = formatValue({
value: '500000',
intlConfig: { locale: 'en-IN', currency: 'INR' },
})
console.log(formattedValue2)
// ₹5,00,000
Solid-JS component for formatting currency and numbers.
The npm package solid-currency-input-field receives a total of 423 weekly downloads. As such, solid-currency-input-field popularity was classified as not popular.
We found that solid-currency-input-field demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 0 open source maintainers collaborating on the project.
Package last updated on 31 Jul 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.