Skip to content

Decimal

Un número decimal exacto. Inmutable.

Properties

units

ts
readonly units: bigint;

El valor, sin coma.


scale

ts
readonly scale: number;

Cuántos dígitos de units quedan a la derecha de la coma.


ZERO

ts
readonly static ZERO: Decimal;

ONE

ts
readonly static ONE: Decimal;

Methods

from()

ts
static from(value): Decimal;

Construye un decimal desde lo que se pueda haber pasado como monto.

Un number se convierte pasando por su representación de texto, así que 0.1 entra como una décima exacta y no como el binario más cercano.

Parameters

ParameterType
valueDecimalLike

Returns

Decimal


parse()

ts
static parse(text): Decimal;

Construye desde una cadena decimal, con o sin notación científica.

Parameters

ParameterType
textstring

Returns

Decimal


add()

ts
add(other): Decimal;

Parameters

ParameterType
otherDecimalLike

Returns

Decimal


sub()

ts
sub(other): Decimal;

Parameters

ParameterType
otherDecimalLike

Returns

Decimal


mul()

ts
mul(other): Decimal;

Parameters

ParameterType
otherDecimalLike

Returns

Decimal


div()

ts
div(other): Decimal;

División con 28 decimales, redondeando a la par.

Parameters

ParameterType
otherDecimalLike

Returns

Decimal


quantize()

ts
quantize(places): Decimal;

Redondea a places decimales, a la mitad hacia arriba.

Parameters

ParameterType
placesnumber

Returns

Decimal


negate()

ts
negate(): Decimal;

Returns

Decimal


cmp()

ts
cmp(other): -1 | 0 | 1;

-1, 0 o 1, según cómo se compare con other.

Parameters

ParameterType
otherDecimalLike

Returns

-1 | 0 | 1


isZero()

ts
isZero(): boolean;

Returns

boolean


isNegative()

ts
isNegative(): boolean;

Returns

boolean


toString()

ts
toString(): string;

El valor como texto, sin ceros de relleno a la derecha.

Returns

string


toNumber()

ts
toNumber(): number;

El valor como number, para serializarlo a JSON.

Returns

number


toJSON()

ts
toJSON(): number;

Returns

number