# Amount · FT4 TypeScript client · Chromia Docs (concept)

> An amount consists of a value and number of decimals. It wraps a
bigint value, and thus has the same limitations as a bigint in terms of size and precision

Source: https://docs.chromia.com/pages/ft4-ts-client/interfaces/asset.Amount/

Interface

# Amount

On this page

* [Properties](#properties)
* [compare](#compare)
* [decimals](#decimals)
* [dividedBy](#dividedby)
* [encodeGtv](#encodegtv)
* [eq](#eq)
* [equals](#equals)
* [gt](#gt)
* [gte](#gte)
* [lt](#lt)
* [lte](#lte)
* [minus](#minus)
* [plus](#plus)
* [times](#times)
* [toString](#tostring)
* [value](#value)
* [Methods](#methods)
* [format](#format)

An amount consists of a value and number of decimals. It wraps a
bigint value, and thus has the same limitations as a bigint in terms of size and precision.

The `Amount` interface also has methods to perform arithmetic operations on the amount with preserved precision.

```signature
interface Amount {
    compare: (other: SupportedNumber) => number;
    decimals: number;
    dividedBy: (other: SupportedNumber, decimals?: number | "max") => Amount;
    encodeGtv: () => RawGtv;
    eq: (other: SupportedNumber) => boolean;
    equals: (other: SupportedNumber) => boolean;
    gt: (other: SupportedNumber) => boolean;
    gte: (other: SupportedNumber) => boolean;
    lt: (other: SupportedNumber) => boolean;
    lte: (other: SupportedNumber) => boolean;
    minus: (other: SupportedNumber) => Amount;
    plus: (other: SupportedNumber) => Amount;
    times: (other: SupportedNumber, decimals?: number | "max") => Amount;
    toString: (removeTrailingZeroes?: boolean) => string;
    value: bigint;
    format(
        which: scientific,
        digits: number,
        removeTrailingZeroes?: boolean,
    ): string;
    format(
        which: fixedDecimals | mixed,
        digits: number,
        removeTrailingZeroes?: boolean,
        groupDigits?: boolean,
    ): string;
}
```

## Properties

### compare

```signature
compare: (other: SupportedNumber) => number
```

Can be used as compareFn with `Array.sort()`.

#### Type Declaration

* ```signature
  (other: SupportedNumber): number
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      amount to compare with

    #### Returns number

    0 if other is equal to this
    1 if other should come before this when sorted
    -1 if other should come after this when sorted

### decimals

```signature
decimals: number
```

### dividedBy

```signature
dividedBy: (other: SupportedNumber, decimals?: number | "max") => Amount
```

Produces a new amount which is the quotient of this amount and the specified value (divisor),
optionally specifying the number of decimals the end result should have.

#### Type Declaration

* ```signature
  (other: SupportedNumber, decimals?: number | "max"): Amount
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to divide this amount with
    - `Optional`decimals: number | "max"

      the number of decimals the end result should have, or "max" for
      the highest value between `this.decimals` and `other.decimals`,
      that is `Math.max(this.decimals, other.decimals)`.
      Defaults to `this.decimals`

    #### Returns [Amount](https://docs.chromia.com/pages/ft4-ts-client/interfaces/asset.Amount/)

    new amount with the value "this amount" / "other amount"

### encodeGtv

```signature
encodeGtv: () => RawGtv
```

Serializes this amount to its `gtv` representation to be used when submitting it to the blockchain

### eq

```signature
eq: (other: SupportedNumber) => boolean
```

Compares this amount with another value and returns true if this amount is **equal** to the other value

#### Type Declaration

* ```signature
  (other: SupportedNumber): boolean
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to compare

    #### Returns boolean

### equals

```signature
equals: (other: SupportedNumber) => boolean
```

Compares this amount with another value and returns true if this amount is **equal** to the other value

#### Type Declaration

* ```signature
  (other: SupportedNumber): boolean
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to compare

    #### Returns boolean

### gt

```signature
gt: (other: SupportedNumber) => boolean
```

Compares this amount with another value and returns true if this amount is **greater than** the other value

#### Type Declaration

* ```signature
  (other: SupportedNumber): boolean
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to compare

    #### Returns boolean

### gte

```signature
gte: (other: SupportedNumber) => boolean
```

Compares this amount with another value and returns true if this amount is **greater than or equal** to the other value

#### Type Declaration

* ```signature
  (other: SupportedNumber): boolean
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to compare

    #### Returns boolean

### lt

```signature
lt: (other: SupportedNumber) => boolean
```

Compares this amount with another value and returns true if this amount is **lesser than** the other value

#### Type Declaration

* ```signature
  (other: SupportedNumber): boolean
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to compare

    #### Returns boolean

### lte

```signature
lte: (other: SupportedNumber) => boolean
```

Compares this amount with another value and returns true if this amount is **lesser than or equal** to the other value

#### Type Declaration

* ```signature
  (other: SupportedNumber): boolean
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to compare

    #### Returns boolean

### minus

```signature
minus: (other: SupportedNumber) => Amount
```

Produces a new amount which is the difference of this amount and the specified value

#### Type Declaration

* ```signature
  (other: SupportedNumber): Amount
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to subtract

    #### Returns [Amount](https://docs.chromia.com/pages/ft4-ts-client/interfaces/asset.Amount/)

    new amount with the value "this amount" - "other amount"

### plus

```signature
plus: (other: SupportedNumber) => Amount
```

Produces a new amount which is the sum of this amount and the specified value

#### Type Declaration

* ```signature
  (other: SupportedNumber): Amount
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to add

    #### Returns [Amount](https://docs.chromia.com/pages/ft4-ts-client/interfaces/asset.Amount/)

    new amount with the value "this amount" + "other amount"

### times

```signature
times: (other: SupportedNumber, decimals?: number | "max") => Amount
```

Produces a new amount which is the product of this amount and the specified value,
optionally specifying the number of decimals the end result should have.

#### Type Declaration

* ```signature
  (other: SupportedNumber, decimals?: number | "max"): Amount
  ```

  + #### Parameters

    - other: [SupportedNumber](https://docs.chromia.com/pages/ft4-ts-client/types/asset.SupportedNumber/)

      the value to multiply this amount with
    - `Optional`decimals: number | "max"

      the number of decimals the end result should have, or "max" for
      the highest value between `this.decimals` and `other.decimals`,
      that is `Math.max(this.decimals, other.decimals)`.
      Defaults to `this.decimals`

    #### Returns [Amount](https://docs.chromia.com/pages/ft4-ts-client/interfaces/asset.Amount/)

    new amount with the value "this amount" \* "other amount"

### toString

```signature
toString: (removeTrailingZeroes?: boolean) => string
```

To be used if you want the precise value, down to the last digit.
It must return a string, as a Number could still be overflowed and floating point
numbers aren't precise in JS.

#### Type Declaration

* ```signature
  (removeTrailingZeroes?: boolean): string
  ```

  + #### Parameters

    - `Optional`removeTrailingZeroes: boolean

      if true, trailing zeroes will be removed (0.800 -> 0.8).
      Defaults to true.

    #### Returns string

### value

```signature
value: bigint
```

## Methods

### format

* ```signature
  format(
      which: scientific,
      digits: number,
      removeTrailingZeroes?: boolean,
  ): string
  ```

  Returns the amount formatted as a readable string

  #### Parameters

  + which: [scientific](https://docs.chromia.com/pages/ft4-ts-client/enums/asset.DecimalFormat/#scientific)

    the DecimalFormat to use
  + digits: number

    the number of digits to display
  + `Optional`removeTrailingZeroes: boolean

    if true, trailing zeroes will be removed (0.800 -> 0.8)

  #### Returns string

  The formatted string. WILL LOSE LOWER DIGIT PRECISION

  #### Example

  TypeScript

  ```
  scientific, 3-digits: 1.00e+18, 2.47e+3, 5.70e+0, 2.30e-4
  fixed decimals, 3-digits: 13.750, 1987352342.435, 0.000, 12
  mixed, 3-digits: 1.00e+18, 1.23e+3, 345, 12.0, 1.45e-1, 1.15e-2 !!NOT 0.01!!
  ```
* ```signature
  format(
      which: fixedDecimals | mixed,
      digits: number,
      removeTrailingZeroes?: boolean,
      groupDigits?: boolean,
  ): string
  ```

  returns the amount formatted as a readable string

  #### Parameters

  + which: [fixedDecimals](https://docs.chromia.com/pages/ft4-ts-client/enums/asset.DecimalFormat/#fixeddecimals) | [mixed](https://docs.chromia.com/pages/ft4-ts-client/enums/asset.DecimalFormat/#mixed)

    the DecimalFormat to use
  + digits: number

    the number of digits to display
  + `Optional`removeTrailingZeroes: boolean

    if true, trailing zeroes will be removed (0.800 -> 0.8)
  + `Optional`groupDigits: boolean

    if true, when the format is not scientific, digits will be grouped by three (1234.5678 -> 1 234.567 8)

  #### Returns string

  The formatted string. WILL LOSE LOWER DIGIT PRECISION

  #### Example

  TypeScript

  ```
  scientific, 3-digits: 1.00e+18, 2.47e+3, 5.70e+0, 2.30e-4
  fixed decimals, 3-digits: 13.750, 1987352342.435, 0.000, 12
  mixed, 3-digits: 1.00e+18, 1.23e+3, 345, 12.0, 1.45e-1, 1.15e-2 !!NOT 0.01!!
  ```

[View this page on docs.chromia.com](https://docs.chromia.com/pages/ft4-ts-client/interfaces/asset.Amount.html)Generated API reference, mirrored from the live docs
