decimalFixedPointToString

function decimalFixedPointToString(value, options?): string;

Returns the canonical decimal string representation of a DecimalFixedPoint.

By default, trailing zeros are trimmed and the decimal point is dropped for whole numbers. Pass options.decimals to emit a different number of fractional digits (with RoundingMode control when scale-down is lossy), and options.padTrailingZeros to emit exactly that many digits. When padTrailingZeros is set without decimals, the output is padded to value.decimals.

Throws SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS when options.decimals forces a lossy rescale under the default 'strict' rounding mode.

Parameters

ParameterType
valueDecimalFixedPoint<Signedness, number, number>
options?FixedPointToStringOptions

Returns

string

Example

const usdc = decimalFixedPoint('unsigned', 64, 6);
decimalFixedPointToString(usdc('42.5'));                               // "42.5"
decimalFixedPointToString(usdc('42.5'), { padTrailingZeros: true });   // "42.500000"
decimalFixedPointToString(usdc('42.678'), { decimals: 2, rounding: 'floor' }); // "42.67"

See

decimalFixedPointToNumber

On this page