dynamic-currency-formatter
Version:
realtime dynamic "Real-time Currency Converter" is an intuitive npm package designed to simplify the formatting and conversion of currency values in real-time for both inputs and static outputs. Whether you're building financial applications, e-commerce p
51 lines (34 loc) • 1.12 kB
Markdown
A lightweight React and JavaScript utility package for real-time currency formatting and static number-to-currency conversions.
- Dynamic input formatting for forms.
- Format static numbers as currency.
- Strip formatting for calculations.
- Configurable currency symbols and decimal precision.
```bash
npm install dynamic-currency-formatter
```
-React Component: CurrencyInput
import { CurrencyInput } from "dynamic-currency-formatter";
function App() {
const [price, setPrice] = useState("");
return (
<CurrencyInput
value={price}
onChange={setPrice}
currencySymbol="$"
placeholder="Enter amount"
/>
);
}
-Format a Number to Currency
import { formatCurrencyInput } from "dynamic-currency-formatter";
const formatted = formatCurrencyInput("12345.678", "$");
console.log(formatted); // Outputs: $12,345.67
-Strip Currency Formatting
import { unformatCurrency } from "dynamic-currency-formatter";
const rawValue = unformatCurrency("$12,345.67");
console.log(rawValue); // Outputs: 12345.67