cmpDecimalFixedPoint

function cmpDecimalFixedPoint<TDecimals>(a, b): -1 | 0 | 1;

Compares two DecimalFixedPoint values and returns -1, 0, or 1 depending on whether a is less than, equal to, or greater than b.

Only the kind and decimals of the two operands must match; signedness and totalBits are allowed to differ because they are storage concerns only and do not affect the mathematical value being compared. Mismatches on the constrained dimensions throw SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH.

Type Parameters

Type Parameter
TDecimals extends number

Parameters

ParameterType
aDecimalFixedPoint<Signedness, number, TDecimals>
bDecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>

Returns

-1 | 0 | 1

Example

const usd = decimalFixedPoint('unsigned', 64, 2);
cmpDecimalFixedPoint(usd('1.25'), usd('2.50')); // -1
cmpDecimalFixedPoint(usd('2.50'), usd('2.50')); // 0
cmpDecimalFixedPoint(usd('3.75'), usd('2.50')); // 1

See

On this page