Our company operates in multiple countries performing transactions with Money with different rounding modes per country. Right now, our code is littered with blocks like this:
Money.with_rounding_mode(country.rounding_mode) do
money_instance.format # or some other money calculation
end
This is error prone and tedious. It's easy to forget to add the block everywhere and it's not safe for async code because with_rounding_mode uses Thread.current.
I think a solution to this would be to have per-instance rounding modes on Money objects and support for with_model_rounding_mode on monetize.
It could be an error to perform an operation on two values with different rounding modes.
What do you think about this approach? Is there a better one?
Our company operates in multiple countries performing transactions with Money with different rounding modes per country. Right now, our code is littered with blocks like this:
This is error prone and tedious. It's easy to forget to add the block everywhere and it's not safe for async code because
with_rounding_mode
usesThread.current
.I think a solution to this would be to have per-instance rounding modes on
Money
objects and support forwith_model_rounding_mode
onmonetize
.It could be an error to perform an operation on two values with different rounding modes.
What do you think about this approach? Is there a better one?