The currency-to-float
package is a dependency-free utility designed to convert currency values into numerical representations without the need to specify the source currency.
You can install currency-to-float
using npm or any other package manager:
npm install currency-to-float
// ESM
import currencyToFloat from 'currency-to-float';
// CommonJs
const { parse } = require('currency-to-float');
const value = currencyToFloat('R$ 1.000,00');
console.log(value); // 1000
Currency | Locale | Input (string) | Output (Number) |
---|---|---|---|
US Dollar ($, USD) | en-US | $12.50 USD | 12.5 |
Brazilian Real (R$, BRL) | pt-BR | R$ 12,50 | 12.5 |
Canadian Dollar ($, CAD) | en-CA | $12.50 CAD | 12.5 |
Canadian Dollar ($, CAD) | fr-CA | 12,50 $ CAD | 12.5 |
Australian Dollar ($, AUD) | en-AU | $12.50 AUD | 12.5 |
Euro (€, EUR) | de-DE, fr-FR | 12,50 € EUR | 12.5 |
Euro (€, EUR) | en-IE | €12.50 EUR | 12.5 |
Euro (€, EUR) | nl-NL | €12,50 EUR | 12.5 |
British Pounds (£, GBP) | en-GB | £12.50 GBP | 12.5 |
Japanese Yen (¥, JPY) | ja-JP | ¥1250 JPY | 1250 |
New Zealand Dollar ($, NZD) | en-NZ | $12.50 NZD | 12.5 |
Hong Kong Dollar ($, HKD) | zh-HK | $12.50 HKD | 12.5 |
Singapore Dollar ($, SGD) | zh-SG | $12.50 SGD | 12.5 |
Danish Krone (Kr, DKK) | da-DK | 12,50 kr. DKK | 12.5 |
Run locally with npm run benchmark
currencyToFloat x 165,114 ops/sec ±5.96% (72 runs sampled)
currency.js x 143,757 ops/sec ±7.27% (66 runs sampled)
Fastest is currencyToFloat
This package is open-source and available under the MIT License.