Options
All
  • Public
  • Public/Protected
  • All
Menu

Represents an arbitrarily large or small number with decimals.

All the arithmetic methods are immutable, i.e. they return a new BigVal instance, leaving the original inputs unchanged.

At any given time a BigVal instance operates at a particular number scale. The scale is based on the the no. of decimals specified in the configuration (BigValConfig).

The min scale is for numbers which do not have decimal places since they are already denominated in the smallest possible unit. The coins scale is for numbers which implicitly have decimal places.

For example, if a given BigVal has decimals = 2 then the following two numbers are equivalent in value:

  • scale = min, value = 100
  • scale = coins, value = 1

If decimals = 18 (this is the default) then the following two numbers are equivalent in value:

  • scale = min, value = 1000000000000000000
  • scale = coins, value = 1

The use of scales like this makes it easy to convert between chain-friendly and user-friendly values and perform arithmetic at the desired precision.

Hierarchy

  • BigVal

Index

Constructors

constructor

  • Parameters

    • src: any

      Input number. If this is a BigVal instance then scale and config parameters will be ignored.

    • Default value scale: string = "min"

      The scale of the input number. Default is min.

    • Default value config: BigValConfig = DefaultBigValConfig

      Custom configuration for this instance.

    Returns BigVal

Properties

add

add: (v: any) => BigVal

Add another number to this one.

Type declaration

div

div: (v: any) => BigVal

Divide this by another number.

Type declaration

eq

eq: (v: any) => boolean

Get whether this is equal to another number.

Type declaration

    • (v: any): boolean
    • Parameters

      • v: any

      Returns boolean

gt

gt: (v: any) => boolean

Get whether this is greater than another number.

Type declaration

    • (v: any): boolean
    • Parameters

      • v: any

      Returns boolean

gte

gte: (v: any) => boolean

Get whether this is greater than or equal to another number.

Type declaration

    • (v: any): boolean
    • Parameters

      • v: any

      Returns boolean

lt

lt: (v: any) => boolean

Get whether this is less than another number.

Type declaration

    • (v: any): boolean
    • Parameters

      • v: any

      Returns boolean

lte

lte: (v: any) => boolean

Get whether this is less than or equal to than another number.

Type declaration

    • (v: any): boolean
    • Parameters

      • v: any

      Returns boolean

mul

mul: (v: any) => BigVal

Multiply with another number.

Type declaration

sub

sub: (v: any) => BigVal

Subtract another number from this one.

Type declaration

Accessors

config

decimalCount

  • get decimalCount(): number
  • Get no. of decimal places in the curent value.

    Returns number

scale

  • get scale(): string

Methods

round

toCoinScale

toFixed

  • toFixed(numDecimals: number): string
  • Get base-10 string representation to given no. of decimal places.

    Parameters

    • numDecimals: number

      No. of decimal places to show.

    Returns string

toMinScale

toNumber

  • toNumber(): number
  • Get base-10 number representation.

    Returns number

toScale

  • toScale(scale: string): BigVal
  • Convert to given scale.

    Parameters

    • scale: string

      Scale to convert to.

    Returns BigVal

toString

  • toString(base?: number): string
  • Get string representation in given base.

    Parameters

    • Default value base: number = 10

      Base to represent in. Default is 10.

    Returns string

Static from

  • Construct a BigVal instance.

    Parameters

    • src: any

      Input number. If this is a BigVal instance then scale and config parameters will be ignored.

    • Default value scale: string = "min"

      The scale of the input number. Default is min.

    • Default value config: BigValConfig = DefaultBigValConfig

      Custom configuration for this instance.

    Returns BigVal

    BigVal instance.

Static fromStr

  • Construct a BigVal instance.

    Parameters

    • numScale: string

      String in form: <number> <scale>. If scale ommitted then min is assumed.

    • Default value config: BigValConfig = DefaultBigValConfig

      Custom configuration for this instance.

    Returns BigVal

    BigVal instance.

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Static method

Generated using TypeDoc