You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
@Padam87 I wonder whether this would not be better solved by having a factory method in your code, which would create Brick\Money instances with desired context and rounding mode, rather than introducing a static configuration to the library.
@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 of static method is just an example here. Virtually all methods hardcode these, so I wouldn't be able to use any of those.
Casting a rational to decimal money the overhead a factory provides is actually worse than specifying context and rounding mode like I do now.
So no for the factory, mainly because it is not useful for anyone wanting to use the built in methods, eg plus, minus etc
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: