Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect database precision #10

Open
sobrinho opened this issue May 8, 2012 · 6 comments
Open

Respect database precision #10

sobrinho opened this issue May 8, 2012 · 6 comments

Comments

@sobrinho
Copy link
Contributor

sobrinho commented May 8, 2012

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?

@carlosantoniodasilva
Copy link
Owner

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.

@sobrinho
Copy link
Contributor Author

sobrinho commented May 8, 2012

Yep, exactly!

Take a look:

@sobrinho
Copy link
Contributor Author

sobrinho commented May 8, 2012

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"

@carlosantoniodasilva
Copy link
Owner

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!

@fmluizao
Copy link

Hi,

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

@carlosantoniodasilva
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants