decimal.js-light is an arbitrary-precision Decimal type for JavaScript, currently at stable version 2.5.1. It is a 'light' version of the more comprehensive `decimal.js` library, specifically optimized for a smaller footprint (12.7 KB minified compared to `decimal.js`'s 32.1 KB). This reduction in size comes with specific tradeoffs: it does not support `NaN`, `Infinity`, or `-0` as legitimate values, nor does it handle numbers in bases other than 10. A key difference in behavior is its approach to rounding; arithmetic operations such as division are truncated at the required precision by default, unlike `decimal.js` where a global rounding mode can apply to such operations. Explicit rounding methods like `toDecimalPlaces` must be called to achieve rounded results. Furthermore, transcendental functions like `naturalExponential`, `naturalLogarithm`, `logarithm`, and `toPower` have a default precision limited to about 100 digits, which can be extended by configuring the `LN10` property. The library also distinguishes its internal `e` property (base 10000000 exponent) from the `exponent()` method (base 10 exponent). The project appears to be actively maintained, with regular updates. It provides TypeScript type declarations.
npm install decimal.js-lightVerified import paths — ran on the pinned version, not inferred.
Initializes the Decimal library with default configuration and performs basic arithmetic operations with arbitrary precision, demonstrating common usage.
Ensure all inputs are valid finite base-10 numbers. If these features are required, consider using the full `decimal.js` library.
Explicitly call rounding methods after arithmetic operations, e.g., `x.dividedBy(y).toDecimalPlaces(N)`.
Increase the maximum precision at runtime by configuring the `LN10` property via `Decimal.set({ LN10: '...' })`. A pre-calculated `LN10` string with sufficient digits for the desired precision must be provided.Always use `myDecimal.exponent()` to retrieve the base 10 exponent. Avoid directly accessing `myDecimal.e` unless working with the internal base 10000000 representation.
For Node.js CommonJS, use `const Decimal = require('decimal.js-light');`. For environments supporting ESM with bundlers (like Webpack or Rollup), use `import Decimal from 'decimal.js-light';`.Ensure all input values are finite base-10 numbers. If `NaN`, `Infinity`, or `-0` support is required, consider using the full `decimal.js` library.
Apply explicit rounding after arithmetic operations using methods like `toDecimalPlaces()`. For example: `x.dividedBy(y).toDecimalPlaces(19).toString()`.
No dependency data recorded yet.