peterolson / BigRational.js

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

a question about toDecimal() #8

Closed element6 closed 10 years ago

element6 commented 10 years ago

Possibly a stupid question, can we just do 'obj.num / obj.denom' (and .toString if want to keep backward compatibility, although I think number makes more sense)?

In what case, would this approach not work over the existing toDecimal()?

Cheers, Gary

element6 commented 10 years ago

nevermind, it's the number of digits, isn't it?

peterolson commented 10 years ago

I'm not sure exactly what you're asking. obj.num / obj.denom will return a Javascript number because bigInts have the valueOf method overloaded.

BigRat(obj.num).over(obj.denom).toDecimal() will do the same thing, except it will be slower and more precise.