getDecimalFixedPointDecoder

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

Returns a decoder for DecimalFixedPoint values of a specific shape. The decoder reads a fixed-size integer using two's-complement for signed values and little-endian byte order by default, and reconstructs a frozen DecimalFixedPoint from the bytes.

Throws SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED when totalBits is not a multiple of 8.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TDecimals extends number

Parameters

ParameterType
signednessTSignedness
totalBitsTTotalBits
decimalsTDecimals
config?FixedPointCodecConfig

Returns

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

Example

const decoder = getDecimalFixedPointDecoder('unsigned', 64, 6);
decoder.decode(bytes); // represents 42.5 for appropriately encoded bytes

See

On this page