binaryFixedPointToBase10

function binaryFixedPointToBase10(value): object;

Converts a BinaryFixedPoint to its exact base-10 representation as a (raw, decimals) pair such that the mathematical value equals raw / 10 ** decimals.

Because 1 / 2 ** F has a finite decimal expansion of exactly F digits, the conversion is always lossless: raw / 2 ** F === (raw * 5 ** F) / 10 ** F. The transformed raw therefore carries exactly fractionalBits decimal digits of precision.

Useful when you want to feed a binary fixed-point into a tool that understands base-10 scaled integers (such as Intl.NumberFormat's string scientific notation).

Parameters

ParameterType
valueBinaryFixedPoint<Signedness, number, number>

Returns

object

NameType
decimalsnumber
rawbigint

Example

const q1_15 = binaryFixedPoint('signed', 16, 15);
binaryFixedPointToBase10(q1_15('0.5'));
// { raw: 500000000000000n, decimals: 15 }

See

BinaryFixedPoint

On this page