-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split money #4
Comments
I'm not sure that it is an important enough method to have in the core project however. For your case, why is it splitting by 1.00? In general, all these pieces of logic like split are quite specific to individual applications. |
I used exactly this mechanism for a Subscription management system, and I think of it as a core mechanism for money handling. I used Fowler's algorithm e.g. (http://stackoverflow.com/questions/1679292/proof-that-fowlers-money-allocation-algorithm-is-correct), and it is used as the basis for a multi-million turnover system. |
I appreciate the need for this now, and have a vague notion about how it might fit in. My theory is that really what is needed is a Money class, with variable precision, and a parallel MoneyCalculator. The calculator can be setup with various rules (like rounding and precision). It then has methods to allow the money to be worked on. This algorithm is one that could be included. The hard part is that the set of algorithms is really variable based on appliction requirements. If the project picks one way, it might not be right for everyone. In the meantime, it seems common enough to consider a split method on Money itself, especially if a pull request is forthcoming. I guess there is the fowler variant using ratios, and the one listed above, which may equate to the same thing but isn't specific. |
I agree with your 'theory'. |
See also #6, which is a very similar request. I think any calculator would have a precision to which it calculates. It would have to keep a record of anything that gets lost along the way, although the detail of that wil be complex no doubt. I also think that the calculator probably should be mutable rather than immutable. I'd like to see some ideas in this area, so if you feel like trying something, I say fork and go-ahead. I'm not sure how your builder fits in for example. I'd suggest writing it up as a prototype first, rather than a full ready to go pull request, so we can brainstorm around the problem. I think the Utils are mostly null-checks, so not really the same thing. Most of the existing methods on Money are useful for one-shot changes - its the multi-step or harder calculations that need extra handling. |
I'm new to git ... |
From https://sourceforge.net/u/jamiem/profile/
https://sourceforge.net/p/joda-money/feature-requests/1/
It would be useful to have a 'split' or 'divide' method like:
Money m = Money.of(CurrencyUnit.GB, 3.99d);
Money[] parts = m.split(4);
// where
// parts[0] == 1.00
// parts[1] == 1.00
// parts[2] == 1.00
// parts[3] == 0.99
The text was updated successfully, but these errors were encountered: