Options
All
  • Public
  • Public/Protected
  • All
Menu

bigdecimal.js

Index

Enumerations

Classes

Functions

Functions

Const Big

  • Constructor function. Can be invoked with new or without new.

    Sample Usage:

    const { Big } = require('bigdecimal.js');
    
    // Constructor accepts any value such as string and BigDecimal itself:
    
    const x = Big('1.1111111111111111111111');
    const y = Big(x);
    
    const z = x.add(y);
    console.log(z.toString()); // 2.2222222222222222222222
    
    
    const u = Big(1.1);
    const v = Big(2n);
    
    // You can also construct a BigDecimal from a number or a BigInt:
    
    console.log(u.toString()); // 1.1
    console.log(v.toString()); // 2
    
    throws

    RangeError on following situations:

    • If value is a number:
      • Value is not a number
      • Value is not in the range [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER)
      • A scale is not provided but a precision is provided
    • If value is converted to string internally and the string format is invalid.

    Parameters

    • n: any

      Any value to build a BigDecimal from. Types other than Number, BigInt and BigDecimal will be internally converted to string and parsed.

    • Optional scale: number

      Scale to use, by default 0.

    • Optional mc: MathContext

      MathContext object which allows you to set precision and rounding mode.

    Returns BigDecimal

Generated using TypeDoc