The light version of decimal.js, an arbitrary-precision Decimal type for JavaScript.
This library is the newest of the family of libraries: bignumber.js, big.js, decimal.js and decimal.js-light.
The API is more or less a subset of the API of decimal.js.
Differences between this library and decimal.js
Size of decimal.js minified: 32.1 KB.
Size of decimal.js-light minified: 12.7 KB.
This library does not include NaN
, Infinity
or -0
as legitimate values, or work with values in other bases.
Here, the Decimal.round
property is just the default rounding mode for toDecimalPlaces
, toExponential
, toFixed
, toPrecision
and toSignificantDigits
. It does not apply to arithmetic operations, which are simply truncated at the required precision.
If rounding is required just apply it explicitly, for example
x = 2;y = 3; // decimal.jsx; // '0.66666666666666666667' // decimal.js-lightx; // '0.66666666666666666666'x; // '0.6666666666666666667'
The naturalExponential
, naturalLogarithm
, logarithm
, and toPower
methods in this library have by default a limited precision of around 100 digits. This limit can be increased at runtime using the LN10
(the natural logarithm of ten) configuration object property.
For example, if a maximum precision of 400 digits is required for these operations use
// 415 digitsDecimal;
Also, in this library the e
property of a Decimal is the base 10000000 exponent, not the base 10 exponent as in decimal.js.
Use the exponent
method to get the base 10 exponent.
Quickstart
Browser:
Node package manager:
$ npm install --save decimal.js-light
// Node.jsvar Decimal = ; // Adjust the global configuration if required (these are the defaults)Decimal; phi = '1.61803398874989484820458683436563811772030917980576'; phi; // '1.6180339887' phi; // true
See the documentation for further information.
TypeScript type declaration file contributed by TANAKA Koichi.