Open LarryBattle opened 12 years ago
For toFixed()
, I think Ratio.parse().valueOf().toFixed()
should work well, unless if there are too many errors with the division.
For example,
(12000/31).toFixed(20) === "387.09677419354841276800"
but should be
(12000/31).toFixed(20) === "387.09677419354838709677"
For tofixed(), you could try something like decimal expansion. Article: http://bateru.com/news/2012/05/code-of-the-day-javascript-decimal-expansion-a-k-a-division/ Bug in article, doesn't support scientific notated values.
Could you try to add these enhancements as a plugin?
toFixed()
: Converts the ratio into a string, keeping a specified number of decimals ( 0 - 20 )(new Ratio).isScientific
: is a property that changes the behavior of how to deal with values that aren't rational. Such as indeterminate forms. Example:Ratio.isScientific = true;
Ratio.parse( 1, 0 ).toLocaleString() == "NaN"