i18n_alchemy icon indicating copy to clipboard operation
i18n_alchemy copied to clipboard

Respect database precision

Open sobrinho opened this issue 12 years ago • 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?

sobrinho avatar May 08 '12 18:05 sobrinho

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.

carlosantoniodasilva avatar May 08 '12 19:05 carlosantoniodasilva

Yep, exactly!

Take a look:

sobrinho avatar May 08 '12 19:05 sobrinho

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"

sobrinho avatar May 08 '12 19:05 sobrinho

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!

carlosantoniodasilva avatar May 08 '12 19:05 carlosantoniodasilva

Hi,

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

fmluizao avatar Oct 27 '15 19:10 fmluizao

@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!

carlosantoniodasilva avatar Dec 19 '15 16:12 carlosantoniodasilva