binaryFixedPointToString

function binaryFixedPointToString(value, options?): string;

Returns the canonical decimal string representation of a BinaryFixedPoint.

Because 1 / 2 ** fractionalBits has a finite decimal expansion, the default output is always exact. This means that values with many fractionalBits can produce long strings — pass options.decimals to cap the output at a desired precision, optionally with a RoundingMode. Use options.padTrailingZeros to emit exactly as many fractional digits as requested; when decimals is omitted, this pads to value.fractionalBits (the full exact expansion length).

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

Parameters

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

Returns

string

Example

const q1_15 = binaryFixedPoint('signed', 16, 15);
binaryFixedPointToString(q1_15('0.5'));                                 // "0.5"
binaryFixedPointToString(q1_15('0.5'), { padTrailingZeros: true });     // "0.500000000000000"
binaryFixedPointToString(ugly, { decimals: 2, rounding: 'round' });     // "0.48"

See

binaryFixedPointToNumber

On this page