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
There are some use cases where we would like to have an object contain both the currency and an amount, but not have the library auto round for us based on currency settings.
An example could be to represent the value of something to a more precise decimal than the currency supports, for purposes of bulk purchases.
A more concrete example could be to set the price of something as $0.057 USD so that when we have 100 of the item, the total cost would be $5.70 USD.
It should be noted arithmetic and logical operations should use this raw value as well.
The text was updated successfully, but these errors were encountered:
proposal: Allow for an option to pass the number of precision to be used
Money.decimal_precision=8# or as a blockMoney.decimal_precision(8)domoney=Money.new(0.12345678,"USD")money.to_s#=> "0.12345678"money.format#=> "0.12"end
by default the decimal precision is set by the currency
How about a decimal_precision keyword argument that is nil by default, which then uses the currency precision. Seems easier to work with than global state, based on the assumption the rounding is often desired and only occasionally not (typically during a series of calculations).
The existing round instance method could be changed to default to the currency precision for rounding, instead of the current 0, providing an easy way to get back to a rounded amount before storing in the database or serializing for APIs.
Description
There are some use cases where we would like to have an object contain both the currency and an amount, but not have the library auto round for us based on currency settings.
An example could be to represent the value of something to a more precise decimal than the currency supports, for purposes of bulk purchases.
A more concrete example could be to set the price of something as $0.057 USD so that when we have 100 of the item, the total cost would be $5.70 USD.
It should be noted arithmetic and logical operations should use this raw value as well.
The text was updated successfully, but these errors were encountered: