RubyMoney/money-rails

10th or 100th of cents support

JensDebergh opened this issue · 1 comments

Hi!

I have a question regarding the money gem. I have a client who needs calculations to be done with a precision bigger than 2. I know this gem handles everything up to a precision of 2 perfectly fine since values are stored as the amount of cents as an integer on the table

But what if I would need a smaller "unit" of the money gem to something smaller than cents. Like 10th of a cent or a 100th of a cent.

A value of 1,14 would result in a value of 1140 stored on the table.

To support a bigger precision:

A value of 1,1445 should be stored as 11445 but the unit needs to change to reflect that this is stored as a unit smaller than cents.

Currently 11445 would convert to 11,45 which isn't what I am looking for.

Since the money gem stores data by default as cents I guess this scenario can't be handled by default by this gem is this correct?

I was wondering if it is possible to configure the money to change the unit to 10th or 100th of a cent to enable these kind of scenarios.

Kind regards
Jens

Hi Jens,

try a custom currency. There is an option called "subunit_to_unit".

For example put into config/initializers/money.rb:

config.register_currency = { :priority => 1, :iso_code => "EU4", :name => "Euro with subunit of 4 digits", :symbol => "EUR", :symbol_first => false, :subunit => "Eurocent", :subunit_to_unit => 10000, :thousands_separator => ".", :decimal_mark => "," }