Search code examples
ruby-on-railscurrencymoney-rails

money rails gem, how to save 6 decimal to field


I have field

monetize :unit_price_cents, as: 'unit_price', with_model_currency: :unit_price_currency

It's type in database is float. And I want to save value in database keep 6 decimal value. in Money GEM, I custom success:

Money.new(1.123456).to_f => 0.01123456

I debug some func, and think the problem in gem money-rails. It round before calling Money.new

So any config or customize could do that? code loading in gem so crazy


Solution

  • So for allowing to use decimal cents. Just add config to initialize/money.rb

    Money.infinite_precision = true
    

    and maybe you want to customize func format of Money gem to show decimal for cent.