All entries
Chapter VIII
Journal · 25 Nov 2026 · 10 min read

Dinero.js vs decimal.js vs BigInt: Money in JS

Dinero.js 2 vs decimal.js vs big.js vs BigInt for money in JavaScript, tested: the 20-digit precision trap, rounding defaults and a 1M-line benchmark.

new Decimal('100.000000000000000001').plus(0) returns 100. No error, no warning. decimal.js parsed the string exactly, then rounded the result of the addition to its default 20 significant digits and threw away one wei. Under the default configuration, any 18-decimal token balance of 100 or more is at risk on every arithmetic call.

The pages that surface for "how to handle money in JavaScript" mostly date from 2018 to 2021. They teach the Dinero v1 API or install alpha packages that are now deprecated, and none of them benchmark the libraries against each other or against BigInt. So I installed dinero.js 2.0.2, decimal.js 10.6.0, big.js 7.0.1, bignumber.js 11.1.5 and currency.js 2.0.4 on Node 24.15 and ran the cases payment code hits. Where I cite no source, the output is from that run.

Why Can't You Use Floats for Money in JavaScript?

Everyone knows 0.1 + 0.2 is 0.30000000000000004. A failure rate is more persuasive. For every price from 0.00 to 99.99, price 100 misses the integer number of pence 1,146 times in 10,000, starting at 0.07 100 = 7.000000000000001.

Math.round(price 100) repairs all 10,000, which is why float code survives so long in production. It stops working once you multiply by a rate. I computed Math.round(net rate * 100) for every net amount from £0.01 to £1,000.00 and compared it with exact integer arithmetic, rounding half up:
RateWrong results out of 100,000First failure
1.2 (20% VAT)0none
1.07259£30.00: 3217 vs 3218
1.17577£4.60: 540 vs 541
1.05105£4.30: 451 vs 452

UK VAT at 20% happens to be clean. The 5% reduced rate is not.

Dinero.js vs decimal.js vs big.js vs currency.js in 2026

Dinero and currency.js model money: an amount with a currency or a fixed precision. decimal.js, big.js and bignumber.js model numbers and know nothing about currencies.

The benchmark is one million invoice lines: unit price times quantity, plus 20% VAT rounded half-even, added to a running total. Median of five runs on an Apple M5 Pro. All eight implementations returned the same 601,440,154,095 pence.

OptionLatest releaseWeekly downloadsGzipped1M lines
Number (integer pence)n/an/a07 ms
BigInt (pence)n/an/a09 ms
big.js 7.0.1Apr 202544.2M3.0 kB354 ms
dinero.js 2.0.2Mar 20261.0M1.6 kB524 ms
bignumber.js 11.1.5Jul 202697.9M8.7 kB670 ms
dinero.js/bigintMar 2026(same package)1.5 kB687 ms
decimal.js 10.6.0Jul 2025148.1M12.9 kB691 ms
currency.js 2.0.4May 20210.97M1.3 kB873 ms

Downloads are npm's count for 17 to 23 November 2026. Sizes are minified, gzipped esbuild bundles. Dinero's is tree-shaken; every function plus all 166 currencies costs 5.3 kB.

Native integers are roughly 50 to 120 times faster than any library, which matters for a reconciliation job over tens of millions of rows. The slowest library still handles 1.1 million lines a second, so for a checkout or an API handler speed should not decide this.

Is Dinero.js v2 Stable? What Changed in 2.0

Yes. Dinero 2.0.0 shipped on 2 March 2026 after years of alphas, and latest on npm now points at 2.0.2. The old @dinero.js/* scoped packages are deprecated in favour of one package with zero dependencies. The API is functions over immutable objects, and an amount is an integer plus a currency plus a scale:

import { dinero, multiply, transformScale, halfEven, toDecimal } from 'dinero.js';
import { GBP } from 'dinero.js/currencies';

const net = dinero({ amount: 123, currency: GBP }); // £1.23 const gross = multiply(net, { amount: 1175, scale: 3 }); // amount 144525, scale 5 toDecimal(transformScale(gross, 2, halfEven)); // "1.45"

Three behaviours to know before adopting it.

Float multipliers fail on some inputs and not others. multiply(d, 1.2) returns 6.00 for £5.00 and throws [Dinero.js] Amount is invalid. for £19.99. It also throws for £1.00 times 1.1, because 100 * 1.1 is 110.00000000000001. A float rate passes every test whose numbers happen to divide evenly. Pass rates as { amount, scale }. The default rounding in transformScale is down. Leave out the third argument above and £1.44525 becomes £1.44. down means towards negative infinity: 0.259 gives 0.25 and -0.259 gives -0.26. The number build has no overflow guard. Adding 2 to an amount of 9007199254740991 returns 9007199254740992 with no error. dinero.js/bigint gets it right, but its currency objects carry bigint fields, so one imported from dinero.js/currencies throws Cannot mix BigInt and other types.

In return you get currency safety: adding USD to EUR throws Objects must have the same currency, which no decimal library will do for you.

What Is decimal.js Default Precision? The 20-Digit Trap

decimal.js is a decimal floating-point library. precision defaults to 20 significant digits and applies to the result of every arithmetic operation. Construction is exact, which is what hides the problem:

const a = new Decimal('100.000000000000000001');
a.toString();                    // "100.000000000000000001"
a.plus(0).toString();            // "100"
a.plus(0).eq(a);                 // false

new Decimal('999999999999999.999998').plus('0.000001').toFixed(); // "1000000000000000" (a 6-decimal USDC amount, off by 0.000001)

Twenty significant digits covers any fiat amount: at two decimals you would need 10¹⁸ pounds. A 6-decimal stablecoin stays exact below 10¹⁴ units. An 18-decimal token stays exact below 100. Decimal.set({ precision: 40 }) fixes it.

big.js and bignumber.js behave differently. Their DP and DECIMAL_PLACES settings, both 20, apply only to division, square roots and negative powers. Addition, subtraction and multiplication are always exact:

Expressiondecimal.jsbig.jsbignumber.js
1000.000000000000000001 + 1e-181000exactexact
123456789012345678901.23 + 0.01123456789012345678900exactexact
1 / 320 digits20 decimals20 decimals
1 / 0InfinitythrowsInfinity
new X('abc')throwsthrowsthrows

One serialisation detail applies to all three. Their toJSON switches to exponent notation at 10⁻⁷ or below and at 10²¹ or above. Ten satoshi, 0.0000001 BTC, serialises as "1e-7", which a strict decimal-string validator on the other side will reject. Call toFixed() at the boundary.

Which Rounding Mode Does Each Library Use?

"Half up" means different things in different libraries. The difference only shows on negative amounts, which in payments means refunds.

Call0.125-0.125
decimal.js, big.js, bignumber.js default (half up)0.13-0.13
dinero halfUp0.13-0.12
dinero halfAwayFromZero0.13-0.13
dinero halfEven0.12-0.12
dinero default (down)0.12-0.13
currency.js0.13-0.12
Intl.NumberFormat default (halfExpand)0.13-0.13

In decimal.js, ROUND_HALF_UP rounds ties away from zero. In Dinero, halfUp rounds ties towards positive infinity, as Math.round does. Port a fee calculation from one to the other, keep the mode name, and a refund comes out a penny different from its charge.

currency.js has the same asymmetry built in with no option to change it: currency(10.075).value is 10.08 and currency(-10.075).value is -10.07. Robin Wieruch wrote up exactly this in June 2024, after cancellation invoices in his system stopped mirroring the originals; he moved to big.js with Big.roundHalfEven. currency.js also parses "abc" as 0, even with errorOnInvalid: true, and reads "1.234,56" as 1.23. Its last stable release was 19 May 2021.

Can You Use BigInt for Money in JavaScript?

Yes. Number.MAX_SAFE_INTEGER is 9,007,199,254,740,991. In pence that is £90 trillion. In 6-decimal USDC base units it is about $9bn, which a treasury total or a SUM over a busy table can cross. At 18 decimals it is 0.009 of a token.

BigInt was only 1.3 times slower than Number in the benchmark. The cost is ergonomic, and most of it fails loudly:

JSON.stringify({ amount: 1999n });   // TypeError: Do not know how to serialize a BigInt
1999n * 1.2;                         // TypeError: Cannot mix BigInt and other types
BigInt('19.99');                     // SyntaxError: Cannot convert 19.99 to a BigInt
Math.max(1n, 2n);                    // TypeError: Cannot convert a BigInt value to a number
-7n / 2n;                            // -3n  (truncates towards zero, silently)

Division is the one silent line, so write a single divRound(n, d, mode) helper and ban the bare / on amounts in review.

JSON needs care in both directions. JSON.parse('{"amount":9007199254740993}').amount is 9007199254740992, wrong before your code sees it. On Node 24 a reviver receives a third context argument carrying the source text, so (k, v, ctx) => BigInt(ctx.source) recovers 9007199254740993n, and JSON.rawJSON(v.toString()) in a replacer writes a BigInt out as a bare number. Sending amounts as strings avoids all of it.

Is Intl.NumberFormat Safe for Currency Decimal Places?

For display, yes. For deriving minor units, no.

format() accepts decimal strings and BigInts and formats them exactly: format('123456789012345678901234.56') gives £123,456,789,012,345,678,901,234.56. As a number, format(900719925474099.93) prints £900,719,925,474,099.90. Feed it toDecimal(d) or x.toFixed(), never Number(x).

The trap is the popular trick of reading resolvedOptions().maximumFractionDigits to find a currency's exponent. I checked all 166 currencies in Dinero's table on Node 24.15 (ICU 78.2, CLDR 48). For sixteen, Intl reports 0 decimals where ISO 4217 says 2 or 3: AFN, ALL, COP, HUF, IDR, IQD, IRR, KPW, LAK, LBP, MGA, MMK, PKR, SOS, SYP and YER.

The answer also moves between runtime versions. CLDR 48 changed COP, HUF, IDR and PKR from 2 digits to 0, and that has already cost someone money. In September 2026 a Drupal Commerce issue reported forint payments reaching Stripe at 1/100 of the order total after a dependency picked up CLDR 48. The fix was to take fraction digits from ISO 4217. CLDR describes how people write prices. ISO describes what a payment API expects.

Dinero has its own oddity: it models MGA and MRU as base 5 with exponent 1, since one ariary is five iraimbilanja, where ISO lists both with two decimals. My ISO 4217 minor units guide has the table of where each PSP deviates. Keep your own exponent table, per provider.

Is JavaScript Getting a Native Decimal Type?

Not soon. The TC39 Decimal proposal is at Stage 1. It specifies IEEE 754 Decimal128, which stores up to 34 significant digits, and its README says the champions "do not envision new literal syntax", so there will be no 1.23m. A related proposal, Amount, which pairs a number with a precision and a unit such as a currency code, is at Stage 2 and still warns of breaking changes. I would not plan around either. Choose from what exists.

My Take: BigInt in the Ledger, a Decimal Library Only for Rates

This part is opinion. Store and move amounts as integers in minor units: number if the value is fiat and provably below 2⁵³, bigint otherwise, and always bigint for tokens. That matches what Stripe, Adyen and card network messages do, and it matches a Postgres bigint column.

Use a decimal library for FX rates, interest and per-unit pricing. There I would pick big.js over decimal.js. It is a quarter of the size, twice as fast in my benchmark and exact on addition and multiplication at any length. It also throws on NaN and on division by zero, where decimal.js returns NaN and Infinity objects that travel through your code until something prints them. decimal.js earns its place if you need logarithms or trigonometry, and payment code does not.

Dinero fits the edges, where currency mix-ups happen: baskets, invoices, multi-currency display. I would not make it the ledger type. The Rust version of this choice is in rust_decimal vs bigdecimal.

What This Means for TypeScript Payment Teams

1. Grep for Decimal.set. If you use decimal.js for token amounts and never raised precision, you have a rounding bug at 21 significant digits. Set it to 40 or move to big.js. 2. Pass Dinero rates as { amount, scale } and always give transformScale an explicit rounding function. 3. Write refund tests. For every rounding call, assert the result for a negative tie such as -0.125. 4. Serialise with toFixed() or toDecimal(), never the default toJSON, and send amounts above 2⁵³ as strings. 5. Do not derive exponents from Intl. Use an ISO 4217 table plus per-PSP overrides. 6. Remove currency.js from payment paths. A silent 0 on bad input is the wrong failure mode for money. 7. Test the 5% rate, not only the 20% one.

I'm Tom Wang, and I write these guides from test output where I can. Rerun the cases against whatever versions you have pinned.

Key Takeaways

  • decimal.js rounds every arithmetic result to 20 significant digits by default, so an 18-decimal token loses precision at 100 units. big.js and bignumber.js add and multiply exactly.
  • Dinero.js 2.0 has been stable since 2 March 2026. Float multipliers fail only on some inputs, and the default rounding is down.
  • "Half up" rounds -0.125 to -0.13 in decimal.js and to -0.12 in Dinero and currency.js.
  • On Node 24.15, Intl.NumberFormat disagrees with ISO 4217 on 16 currencies, including HUF, IDR, COP and PKR.