Class Decimal128

A class representation of the BSON Decimal128 type.

Hierarchy

Constructors

  • Parameters

    • bytes: string | Uint8Array

      a buffer containing the raw Decimal128 bytes in little endian order, or a string representation as returned by .toString()

    Returns Decimal128

Properties

bytes: Uint8Array
_fromString: any

Accessors

  • get _bsontype(): "Decimal128"
  • Returns "Decimal128"

Methods

  • Prints a human-readable string of BSON value information If invoked manually without node.js.inspect function, this will default to a modified JSON.stringify

    Parameters

    • Optional depth: number
    • Optional options: unknown
    • Optional inspect: InspectFn

    Returns string

  • Create a string representation of the raw Decimal128 value

    Returns string

  • Create a Decimal128 instance from a string representation

    Parameters

    • representation: string

      a numeric string representation.

    Returns Decimal128

  • Create a Decimal128 instance from a string representation, allowing for rounding to 34 significant digits

    Parameters

    • representation: string

      a numeric string representation.

    Returns Decimal128

    Example

    Example of a number that will be rounded

    > let d = Decimal128.fromString('37.499999999999999196428571428571375')
    Uncaught:
    BSONError: "37.499999999999999196428571428571375" is not a valid Decimal128 string - inexact rounding
    at invalidErr (/home/wajames/js-bson/lib/bson.cjs:1402:11)
    at Decimal128.fromStringInternal (/home/wajames/js-bson/lib/bson.cjs:1633:25)
    at Decimal128.fromString (/home/wajames/js-bson/lib/bson.cjs:1424:27)

    > d = Decimal128.fromStringWithRounding('37.499999999999999196428571428571375')
    new Decimal128("37.49999999999999919642857142857138")

Generated using TypeDoc