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

Possible ratio.js plugins

Open LarryBattle opened this issue 13 years ago • 2 comments

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"

LarryBattle avatar Oct 05 '12 18:10 LarryBattle

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"

LarryBattle avatar Oct 15 '12 02:10 LarryBattle

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.

LarryBattle avatar Oct 22 '12 05:10 LarryBattle