Any value to build a BigDecimal from. Types other than Number
, BigInt
and BigDecimal
will be internally
converted to string and parsed.
Scale to use, by default 0.
MathContext object which allows you to set precision and rounding mode.
Constructor function for MathContext. Can be invoked with new or without new.
Sample Usage:
const { Big, MathContext, RoundingMode } = require('bigdecimal.js');
const x = Big('1');
const y = Big('3');
const res1 = x.divide(y, new MathContext(3));
console.log(res1.toString()); // 0.333
const res2 = x.divide(y, MathContext(3, RoundingMode.UP)); // You can also use without `new` operator
console.log(res2.toString()); // 0.334
try {
x.divide(y);
// throws since full precision is requested but it is not possible
} catch (e) {
console.log(e); // RangeError: Non-terminating decimal expansion; no exact representable decimal result.
}
Precision value
Rounding Mode
Generated using TypeDoc
Constructor function for BigDecimal. Can be invoked with new or without new.
Sample Usage:
RangeError on following situations: