addDecimalFixedPoint

function addDecimalFixedPoint<TSignedness, TTotalBits, TDecimals>(
    a,
    b,
): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>;

Adds two DecimalFixedPoint values of the same shape and returns the result at the same shape.

Throws SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH if the two operands differ in signedness, total bits, or decimals, and SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW if the sum does not fit the target shape.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TDecimals extends number

Parameters

ParameterType
aDecimalFixedPoint<TSignedness, TTotalBits, TDecimals>
bNoInfer<DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>>

Returns

DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>

Example

const usd = decimalFixedPoint('unsigned', 64, 2);
addDecimalFixedPoint(usd('1.50'), usd('2.25')); // represents 3.75

See

subtractDecimalFixedPoint

On this page