carlosantoniodasilva/i18n_alchemy

Respect database precision

Opened this issue · 6 comments

Hi mate :)

We are working in a project that have a lot of decimal columns with different precisions.

Currently we are workarounding with decorators:

class PublicityDecorator < Decorator
  def value
    helpers.number_with_precision super, :precision => 4
  end
end

I think where we want to display a different precision is where we should implement something like decorators to override precision.

What you think?

You mean: finding a way to bring the current database precision to show in the localized version of the attribute?

Right now it uses the default precision in locale config, but that's something we could think about yeah.

Yep, exactly!

Take a look:

Sorry, submitted without code:

irb(main):002:0> publicity.value
=> #<BigDecimal:7f8e7bf4cc00,'0.30015E2',18(18)>
irb(main):003:0> publicity.value.to_s
=> "30.015"
irb(main):004:0> publicity.localized.value
=> "30,02"

But I'm expecting this:

irb(main):006:0> helper.number_with_precision publicity.value, :precision => 3
=> "30,015"

Got it.. sounds reasonable to me yeah, will make our life easier. Just need to figure out a good way to handle the case, because parsing / localizing is untied from column lookup.

I have to finish and merge some other stuff onto master, then I'll try to look this, thanks!

Hi,

Any news on this? If you point me the direction I can work in a PR.

@fernandoluizao no news, sorry - I have to circle back and review this more carefully, it seems to make sense to respect that option, but I'm not sure how it'll conflict with the locale yet. If you have some time to play with it, please feel free to go ahead :). Thanks!