# Class Decimal

`Decimal` provides support for correct rounded floating point arithmetic, unlike the standard `Number` type. It also supports user-defined precision (default is 20 decimal places), which can be as large as needed.

• Decimal

## Constructors

• Returns a new `Decimal` instance from the value or `0`.

## Properties

PRECISION: number = 20

## Accessors

• get precision(): number
• #### Returns number

• set precision(value: number): void

## Methods

• Returns a new `Decimal` that is the sum of this and `x`.

### Example

``````let a = decimal('50000000000')let b = decimal('0.000000005')a.add(b)  // 50000000000.000000005
``````

### Returns

#### Returns Decimal

• Returns a comparison value representing the ordering of this value in respect to `x`.

• `-1` if this < x
• `1` if this > x
• `0` if this == x

### Returns

#### Returns 1 | -1 | 0

• Returns a new `Decimal` that is the quotient of this and `x`

### Example

``````let a = decimal('1')let b = decimal('3')a.div(b)  // 0.333333333333333333333333333333
``````

### Returns

#### Returns Decimal

• Returns `true` if this value is equal to the value of `x`, otherwise `false`.

### Returns

other

#### Returns boolean

• Returns `true` if this value is greater than the value of `x`, otherwise `false`.

### Returns

#### Returns boolean

• Returns `true` if this value is greater than or equal to the value of `x`, otherwise `false`.

### Returns

#### Returns boolean

• Returns `true` if this value is less than the value of `x`, otherwise `false`.

### Returns

#### Returns boolean

• Returns `true` if this value is less than or equal to the value of `x`, otherwise `false`.

### Returns

#### Returns boolean

• Returns a new `Decimal` that is the product of this and `x`.

### Example

``````let a = decimal('0.0000000000000000000025')let b = decimal('400000000000000000000')a.mul(b)  // 1
``````

### Returns

#### Returns Decimal

• Returns a new `Decimal` that has the opposite sign of this `Decimal`.

### Example

``````let a = decimal('5')a.negated()  // -5
``````

### Returns

#### Returns Decimal

• Returns the square root of this `Decimal`.

### Returns

#### Returns Decimal

• Returns a new `Decimal` that is the difference between this and `x`.

### Example

``````let a = decimal('1')let b = decimal('0.0000000000000000001')a.sub(b)  // 0.9999999999999999999
``````

### Returns

#### Returns Decimal

• Converts this decimal to the `Number` value

### Returns

#### Returns number

• Returns a string representation of this decimal.

### Returns

#### Returns string

Generated using TypeDoc