rawDecimalFixedPoint

function rawDecimalFixedPoint<TSignedness, TTotalBits, TDecimals>(
    signedness,
    totalBits,
    decimals,
): (raw) => DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>;

Returns a factory that constructs DecimalFixedPoint values from a raw bigint in the smallest representable unit (i.e. already scaled by 10 ** decimals).

The outer call validates the shape parameters once and the returned factory can be called many times to construct values of that shape.

The raw value is range-checked against the claimed totalBits and signedness; no rounding is ever required.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TDecimals extends number

Parameters

ParameterType
signednessTSignedness
totalBitsTTotalBits
decimalsTDecimals

Returns

(raw): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>;

Parameters

ParameterType
rawbigint

Returns

DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>

Example

const cents = rawDecimalFixedPoint('unsigned', 16, 2);
cents(425n); // Represents 4.25

See

On this page