BigRational.js icon indicating copy to clipboard operation
BigRational.js copied to clipboard

toString() to support different base.

Open roccomuso opened this issue 6 years ago • 5 comments

I'd like to achieve something like:

BigRat(12.90).toString(16)

Like BigInteger.js (http://mikemcl.github.io/bignumber.js/#toS).

roccomuso avatar Feb 11 '19 12:02 roccomuso

In this case you would want bigRat(12.90).toString(16) to return 81/a?

peterolson avatar Feb 14 '19 00:02 peterolson

On BigNumber.js you'd get something like c.e666666666668

roccomuso avatar Feb 14 '19 01:02 roccomuso

toString returns numbers in the numerator/denominator format. The toDecimal method returns a decimal approximation. Maybe you want toDecimal to support different bases?

peterolson avatar Feb 14 '19 02:02 peterolson

Yes

roccomuso avatar Feb 14 '19 02:02 roccomuso

Perhaps a toBase(n) function could be implemented? I second this idea of multiple base formats.

austindd avatar Aug 14 '20 07:08 austindd