Tema
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
| Parameter | Type |
|---|---|
value | DecimalLike |
Returns
Decimal
parse()
ts
static parse(text): Decimal;Construye desde una cadena decimal, con o sin notación científica.
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
Decimal
add()
ts
add(other): Decimal;Parameters
| Parameter | Type |
|---|---|
other | DecimalLike |
Returns
Decimal
sub()
ts
sub(other): Decimal;Parameters
| Parameter | Type |
|---|---|
other | DecimalLike |
Returns
Decimal
mul()
ts
mul(other): Decimal;Parameters
| Parameter | Type |
|---|---|
other | DecimalLike |
Returns
Decimal
div()
ts
div(other): Decimal;División con 28 decimales, redondeando a la par.
Parameters
| Parameter | Type |
|---|---|
other | DecimalLike |
Returns
Decimal
quantize()
ts
quantize(places): Decimal;Redondea a places decimales, a la mitad hacia arriba.
Parameters
| Parameter | Type |
|---|---|
places | number |
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
| Parameter | Type |
|---|---|
other | DecimalLike |
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
