toUnsignedDecimalFixedPoint

function toUnsignedDecimalFixedPoint<TTotalBits, TDecimals>(
    value,
): DecimalFixedPoint<'unsigned', TTotalBits, TDecimals>;

Converts a DecimalFixedPoint to its unsigned equivalent at the same totalBits and decimals.

Unsigned inputs are returned by reference unchanged; signed inputs are accepted as long as their raw value is non-negative.

Throws SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE when the input represents a negative value that cannot be stored as unsigned.

Type Parameters

Type Parameter
TTotalBits extends number
TDecimals extends number

Parameters

ParameterType
valueDecimalFixedPoint<Signedness, TTotalBits, TDecimals>

Returns

DecimalFixedPoint<"unsigned", TTotalBits, TDecimals>

Example

const signedUsd = decimalFixedPoint('signed', 64, 2);
toUnsignedDecimalFixedPoint(signedUsd('1.50')); // unsigned, raw unchanged
toUnsignedDecimalFixedPoint(signedUsd('-1'));   // throws

See

toSignedDecimalFixedPoint

On this page