-
-
Notifications
You must be signed in to change notification settings - Fork 96
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
Ability to set default context and rounding mode #59
Comments
@Padam87 I wonder whether this would not be better solved by having a factory method in your code, which would create |
@nufue Unfortunately that is not a way to go here. First off, this is a library problem, I always prefer a built in solution for these. Second, the So no for the factory, mainly because it is not useful for anyone wanting to use the built in methods, eg |
BTW, there is already an issue here, #38 That would also be a solution for this, as I could add a shorthand for myself. |
I would like to open a discussion about the possibility of implementing a way to override the context, and rounding mode of money methods.
These are hard coded all the way, and I personally find it pretty annoying, and ugly that I have to specify what I would like to do.
99.99% of the time I use my own context, and a RoundingMode::HALF_UP.
This is because in real use case scenarios the money object is always constrained by the database schema.
For example: We use 6 decimals because we work with really small, really preciese values.
Let's say the price of a single sheet of paper is 0.123456 EUR. Rounding that to 0.12 and storing it is a no-go, considering you literally need millions of these printed sometimes, and that could make a huge difference - a loss.
Calculations are always done in Rational, and cast to Money at the very end, to avoid rounding as much as possible of course, but the end is always the database scale and precision.
Long story short: DefaultContext is not viable for everyone.
Could we make some changes here that would allow global configuration?
(This might be the rare case when I'm not against the use of a singleton for configuration)
Proposal:
The text was updated successfully, but these errors were encountered: