Closed namxam closed 1 year ago
Division of money returns an array of equal amounts with one holding the remainder.
iex> Money.divide(Money.new(9, :USD), 4)
[
%Money{amount: 3, currency: :USD},
%Money{amount: 2, currency: :USD},
%Money{amount: 2, currency: :USD},
%Money{amount: 2, currency: :USD}
]
How do you propose Money.divide(Money.t, float)
would work?
Ok, sorry, then I did not read the documentation correctly. But this seems to be extremely counterintuitive. I have never seen a division
to be implemented like this.
To be honest I would expect this function to be named like "split" or something similar. Because add
, multiply
, and subtract
are implemented just like their basic arithmetic operation counterparts.
When you work with money, the literal stuff, how do you divide it?
When you add money, you take two amounts and you have a new amount When you subtract money, you remove an amount and you are left with a new amount When you invest and multiply your money, you increase it and are left with a new amount But when you divide your money up, you are left with multiple amounts.
Yeah, but actually isn't it the case for any value? It just feels really unnatural. I probably would have gone with a different verb … like split
. I am not a native speaker, but I think you also say split a bill and not divide a bill.
For what its worth we had a similar discussion in my company. We use the divide
function as a split, and we were surprised to see that it supported the use case of dividing by a negative amount.
What about calculating percentages with division?
Is there a reason why division are only supported by integers? If not, I would try to fix it and submit a pull request.