🌐
Mikemcl
mikemcl.github.io › decimal.js
decimal.js API
Returns a new Decimal whose value is the value of this Decimal raised to the power x, rounded to precision significant digits using rounding mode rounding. The performance of this method degrades exponentially with increasing digits.
🌐
Mikemcl
mikemcl.github.io › decimal.js-light
decimal.js-light API
Returns a new Decimal whose value is the value of this Decimal raised to the power x, truncated to precision significant digits. The performance of this method degrades exponentially with increasing digits.
🌐
Medium
medium.com › @josephgathumbi › decimal-js-vs-c1471b362181
Decimal.js vs. BigNumber.js: Which One Should You Use for High-Precision Arithmetic and Large Numbers? | by Joseph | Medium
January 30, 2025 - Decimal.js: Slightly slower for basic operations due to its extensive feature set and precision handling. BigNumber.js: Optimized for speed, making it a better choice for performance-sensitive applications.
🌐
MeasureThat
measurethat.net › Benchmarks › Show › 12367 › 0 › bignumberjs-vs-bigjs-vs-decimaljs-i
Benchmark: bignumber.js vs. big.js vs. decimal.js (I) - MeasureThat.net
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9) bignumber.js vs. big.js vs. decimal.js (I) no native · bignumber.js vs. big.js vs. decimal.js (without native) Native.toFixed() vs bignumber.js vs big.js vs decimal.js · bignumber.js vs. big.js vs. [email protected] (I) Comments ·
🌐
MeasureThat
measurethat.net › Benchmarks › Show › 13963 › 0 › decimaljs-vs-native
Benchmark: decimal.js vs. native - MeasureThat.net
bignumber.js vs. big.js vs. decimal.js (I) toFixed(9) bignumber.js vs. big.js vs. decimal.js (I) no native · bignumber.js vs. big.js vs. decimal.js (without native) number / bignumber.js / big.js / decimal.js · Native.toFixed() vs bignumber.js vs big.js vs decimal.js ·
🌐
DEV Community
dev.to › fvictorio › a-comparison-of-bignumber-libraries-in-javascript-2gc5
A comparison of BigNumber libraries in JavaScript - DEV Community
November 28, 2020 - Finally I'll give you my advice on which one to use (spoiler alert: it's big.js). The following table shows the libraries I picked and some aspects of each one. There are a lot of other things you might want to consider, like their API, performance, supported operations, etc., but this should give you a place to start. All of them support integer values, but decimal.js, by design, can lose precision (more on this later).
Top answer
1 of 2
1

I have some experience using both of these libraries, so I will do my best to explain each of them:

Intl.NumberFormat and decimal.js are both libraries in JavaScript that can be used to format and manipulate numbers. However, while they are similar in some ways, they are very different in others.

Intl.NumberFormat is a built-in JavaScript library that provides localization support for number formatting, including decimal and grouping separators, decimal precision, and currency formatting. It is widely used to format numbers based on a user's language and region.

Decimal.js is a third-party library that provides arbitrary-precision decimal arithmetic for JavaScript. It allows for precise calculations with decimal numbers, which are often required in financial and scientific applications where rounding errors can have significant consequences.

Although Intl.NumberFormat can handle basic currency formatting, it may not be suitable for all use cases. For example, it may not handle more complex currency formatting requirements, such as rounding rules or multiple currencies in the same document. In such cases, decimal.js can provide more precise and flexible currency handling capabilities.

I hope this answered your question!

2 of 2
0

I agree to Promaster's answer, it's also worth noting that using the decimal.js library may have performance implications, as it is a third-party library that requires additional processing overhead compared to the built-in Intl.NumberFormat library. Therefore, you should consider the specific requirements of your application when deciding whether to use decimal.js or Intl.NumberFormat.

The main benefit of using the decimal.js library over Intl.NumberFormat is the ability to perform precise mathematical operations on decimal numbers. If your application requires this level of precision, then decimal.js may be a better choice. However, if your application only requires formatting numbers for display, then Intl.NumberFormat may be sufficient.

🌐
GitHub
github.com › MikeMcl › big.js
GitHub - MikeMcl/big.js: A small, fast JavaScript library for arbitrary-precision decimal arithmetic. · GitHub
A small, fast JavaScript library for arbitrary-precision decimal arithmetic. - MikeMcl/big.js
Author   MikeMcl
🌐
Azurewebsites
benchmarklab.azurewebsites.net › Benchmarks › Show › 27834 › 0 › number-bignumberjs-bigjs-decimaljs
Benchmark: number / bignumber.js / big.js / decimal.js - MeasureThat.net
JavaScript benchmarks, JavaScript performance playground. Measure performance accross different browsers. javascript benchmarks online.
Find elsewhere
🌐
Progress
progress.com › blogs › decimals-no-limitations-javascript
Decimals with No Limitations in JavaScript
November 13, 2024 - In this blog, we will highlight the key characteristics of decimals. We will also go through the representation of decimals in JSON payload. And finally, we will explore what options you have for configuring decimals for maximum performance and if you need to deal with extremely large or small ...
🌐
GitHub
github.com › tc39 › proposal-decimal
GitHub - tc39/proposal-decimal: Built-in exact decimal numbers for JavaScript · GitHub
In some application architectures, JS only deals with a string representing a human-readable decimal quantity (e.g, "1.25"), and never does calculations or conversions. However, several trends push towards JS’s deeper involvement in with decimal quantities: More complicated frontend architectures: Rounding, localization or other presentational aspects may be performed on the frontend for better interactive performance.
Author   tc39
🌐
Reddit
reddit.com › r/incremental_games › break_infinity.js - a performance-designed replacement for decimal.js for incremental games that use very large numbers
r/incremental_games on Reddit: break_infinity.js - a performance-designed replacement for decimal.js for incremental games that use VERY large numbers
October 10, 2017 -

https://github.com/Patashu/break_infinity.js

I made this library because decimal.js is very slow, both because it focused on arbitrary precision, and because its functions were not coded with performance in mind to begin with.

By relaxing the arbitrary precision requirement (mantissa is now just a javascript Number, rather than an array of strings, and exp and pow only guarantee about 9 decimal places of accuracy), compared to decimal.js, operations of break_infinity.js are anywhere from 50x to 1000x faster.

How fast is it in practice? Antimatter Dimensions swapped from decimal.js to break_infinity.js in its Eternity Update that came out today ( https://www.reddit.com/r/incremental_games/comments/7grvhl/antimatter_dimensions_eternity_update/ ), and in doing so, the time spent in scripts was reduced to 22% of what it used to be. Obviously if your incremental game is not as math-heavy as Antimatter Dimensions it won't benefit to the same extent, but performance is performance.

Like decimal.js, break_infinity.js handles numbers as large as 1e(9e15). Above that (if you even GET that far), you should use break_break_infinity.js instead, which goes up to 1e(1.79e308), though note that it hasn't been thoroughly tested yet, and obviously it will lose on performance compared to break_infinity.js since it uses a big-integer library for the exponent instead of just a Number.

If you find any bugs or wish to contribute, check out the issues on the github repository ( https://github.com/Patashu/break_infinity.js/issues ) or open a pull request (or message me on Reddit, I guess).

🌐
GitHub
github.com › MikeMcl › decimal.js
GitHub - MikeMcl/decimal.js: An arbitrary-precision Decimal type for JavaScript · GitHub
An arbitrary-precision Decimal type for JavaScript. ... The library is similar to bignumber.js, but here precision is specified in terms of significant digits rather than decimal places, and all calculations are rounded to the precision (similar ...
Author   MikeMcl
🌐
NPM Compare
npm-compare.com › big.js,bignumber.js,decimal.js,decimal.js-light
decimal.js vs bignumber.js vs big.js vs decimal.js-light | JavaScript Arbitrary-Precision Decimal Libraries
big.js provides arbitrary precision for decimal arithmetic, ensuring that calculations are accurate and free from floating-point errors. It is designed for performance and is particularly effective for basic arithmetic operations without sacrificing precision.
Top answer
1 of 2
2

Generally no. There are some possible performance implications when a number doesn't fit in a 31b signed int.

A tour of V8: object representation explains

According to the spec, all numbers in JavaScript are 64-bit floating point doubles. We frequently work with integers though, so V8 represents numbers with 31-bit signed integers whenever possible (the low bit is always 0; this helps the garbage collector distinguish numbers from pointers). So objects with the fast small integers elements kind only contain this type of number. If we want to store a fractional number or a larger integer or a special value like -0, then we need to upgrade the array to fast doubles. This involves a potentially expensive copy-and-convert operation, but it doesn't happen often in practice. fast doubles objects are still pretty fast because all of the numbers are stored in an unboxed representation. If we want to store any other kind of value, e.g., a string or an object, we must upgrade to a general array of fast elements.

2 of 2
0

Does the amount of decimals in the numbers used (precision) affect performance especially in JavaScript? If it does, how?

No. The number type in JavaScript is a 64-bit floating-point value with base 2 and always has the same precision. The computer works on that data bit by bit and it doesn't matter whether that data represents something that looks simple to a human like 1.0 or something seemingly complicated like 123423.5645632. In fact, for base 2 floats, the 'human' values are just as 'hard', because 1.1 is truly represented by a much longer number (sth. like 1.10000000000000054). All this doesn't matter, because the computer truly operates on 64 ones and zeros. There are always some arcane exceptions in floating point, but those usually don't matter in practice.

How about saving numbers in MongoDB: Do precise numbers take more space than less precise ones?

Decimal numbers are stored as doubles (64bit), and it doesn't matter whether that is 1.0 or 1.1221234423. Again, the number of bits is constant for these data types.

The same is true for ints, but MongoDB has support for both 32- and 64-bit ints. So NumberLong is indeed larger than regular 32-bit ints and just as large as doubles.

🌐
npm
npmjs.com › package › decimal.js › v › 2.0.0
decimal.js - npm
An arbitrary-precision Decimal type for JavaScript. Faster, smaller, and perhaps easier to use than JavaScript versions of Java's BigDecimal ... The library is similar to bignumber.js, but here precision is specified in terms of significant digits instead of decimal places, and all calculations are rounded to the precision (similar to Python's decimal module) rather than just those involving division.
      » npm install decimal.js
    
Published   Jul 06, 2025
Version   2.0.0
Author   Michael Mclaughlin
🌐
DEV Community
dev.to › lucaspereiradesouzat › decimal-javascripts-future-numeric-type-1905
Decimal: JavaScript's future numeric type - DEV Community
December 29, 2025 - While efficient for most use cases, this representation can lead to subtle inaccuracies in certain operations. The fundamental reason lies in how decimal numbers are converted to binary.
🌐
Babylon.js
forum.babylonjs.com › questions
Some recommended big decimals library to use besides BabylonJs? - Questions - Babylon.js
June 1, 2021 - Hello. I’m working in a motion class for my babylonjs project and I have some issues interpolating arrays of numbers. I believe this is caused for the javascript floating point precision issues: [Link] Is there some r…