currency.js is a lightweight JavaScript library specifically designed for accurate financial calculations and handling currency values, aiming to circumvent common floating-point precision issues inherent in JavaScript's number type. The current stable version is 2.0.4, with recent releases primarily focusing on critical bug fixes related to the `fromCents` option and minor security updates to development dependencies. The library provides a simple, fluent API for creating currency objects, performing arithmetic operations (add, subtract, multiply, divide), and robust formatting capabilities. It supports various international currency formats, custom patterns, and precision settings, making it a suitable choice for applications requiring reliable money management without the overhead of larger, more complex financial libraries. Its key differentiator is its small footprint and dedicated focus on fixed-point arithmetic for ensuring precision in monetary calculations.
npm install currency.jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic instantiation, arithmetic operations, custom formatting, and handling values explicitly as cents.
If you were using a string for the `formatter` option, you must update your code to either provide a function that returns the formatted string, or an object with specific formatting properties like `symbol`, `separator`, etc.
Review all instances where `fromCents: true` is used. Adjust your input values accordingly to ensure they represent the total cents rather than decimal currency amounts.
Upgrade to `currency.js@2.0.4` or later to ensure correct calculations, especially when using the `fromCents` option. Thoroughly test your application's financial logic after upgrading.
If migrating from versions older than `1.2.0`, re-verify critical financial calculations to ensure consistent results, as internal precision handling was adjusted.
Change the `formatter` option to either a function that returns the formatted string or an object specifying formatting properties. Example: `{ formatter: (value) => `$${value}` }` or `{ formatter: { symbol: '$', separator: ',', decimal: '.' } }`.For versions `v2.0.4` and above, ensure your input value is the exact number of cents (e.g., `currency(2500, { fromCents: true })` for $25.00). If you are on an older `v2.x` release, upgrade to `v2.0.4` or newer to resolve the calculation bugs.Always call `.format()` on the `currency` object instance to get the formatted string (e.g., `myCurrencyValue.format()`). Review options like `pattern`, `separator`, `decimal`, and `symbol` for correct display.
No dependency data recorded yet.