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

feature request: allocate method

Open NathanC opened this issue 3 years ago • 1 comments

Some other libraries like Dinero.js have an allocate method, similar to distribute but taking percentages or ratios. e.g., `currency(2.00).allocate(50, 25, 25) would result in [1.00, 0.50, 0.50].

This would be a very useful feature! Are there any plans for it? If not, does anyone have a code snippet that does this for currency.js? It's not super hard to implement oneself, which is what I'm doing, but with currency calculation I like to be very careful so any examples are appreciated. The only real complexity is allocating sums that don't nicely distribute over the percentages given.

NathanC avatar Oct 26 '22 23:10 NathanC

Interesting, I would imagine we could support something similar (as of right now currency.js assumes an equal distribution, and spreads pennies over anything unequal). I'll leave this open to see if anyone else is interested and would provide a proposal on the API.

scurker avatar Nov 08 '22 23:11 scurker