peterolson / BigRational.js

An arbitrary length rational number library for Javascript
The Unlicense
47 stars 15 forks source link

toString() to support different base. #35

Open roccomuso opened 5 years ago

roccomuso commented 5 years ago

I'd like to achieve something like:

BigRat(12.90).toString(16)

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

peterolson commented 5 years ago

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

roccomuso commented 5 years ago

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

peterolson commented 5 years ago

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

roccomuso commented 5 years ago

Yes

austindd commented 4 years ago

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