Skip to content

rationalToDecimalString

rationalToDecimalString(value, places): string

Defined in: packages/math-numbers/src/rational/rational-to-decimal-string.ts:23

p/q written out with exactly places decimal places.

Truncated rather than rounded, then made sticky: when the division leaves a remainder the last digit is forced odd, so rounding this numeral to fewer places lands where rounding the exact value would. Without that, a caller that rounds afterwards rounds twice, and a truncation that happened to land on a tie breaks the wrong way.

The sticky digit is why this is not simply decimalDiv on the two parts: it encodes “there is more below” in a form any later rounding respects.

Readonly<Rational>

The rational to expand. Its denominator is positive by invariant.

number

Decimal places to emit.

string

The numeral, with places digits after the point.

If places is not a non-negative integer.