getDecimalFixedPointCodec

function getDecimalFixedPointCodec<TSignedness, TTotalBits, TDecimals>(
    signedness,
    totalBits,
    decimals,
    config?,
): FixedSizeCodec<
    DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,
    DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,
    BytesForTotalBits<TTotalBits>
>;

Returns a codec for DecimalFixedPoint values of a specific shape, combining getDecimalFixedPointEncoder and getDecimalFixedPointDecoder.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TDecimals extends number

Parameters

ParameterType
signednessTSignedness
totalBitsTTotalBits
decimalsTDecimals
config?FixedPointCodecConfig

Returns

FixedSizeCodec<DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>, DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>, BytesForTotalBits<TTotalBits>>

Example

const codec = getDecimalFixedPointCodec('unsigned', 64, 6);
const bytes = codec.encode(decimalFixedPoint('unsigned', 64, 6)('42.5'));
const value = codec.decode(bytes); // represents 42.5

See

On this page