This project is archived and is in readonly mode.
Another rounding problem in number_with_precision
-
Piotr Sarnacki
- Importance changed from to Low
I would apply this patch, but it works only on 1.9, on 1.8 I get one failure:
1) Failure: test_number_with_precision(NumberHelperTest) [./test/template/number_helper_test.rb:105:in `test_number_with_precision' /users/drogus/projekty/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `__send__' /users/drogus/projekty/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:67:in `run' /users/drogus/projekty/rails/activesupport/lib/active_support/callbacks.rb:426:in `_run_setup_callbacks' /users/drogus/projekty/rails/activesupport/lib/active_support/testing/setup_and_teardown.rb:65:in `run']: <"10.0"> expected but was <"9.99">. -
Repository
- State changed from new to resolved
(from [006ec77e60163d57d655479602230672d98e0f10]) Fixed number_with_precision rounding error [#6182 state:resolved] https://github.com/rails/rails/commit/006ec77e60163d57d655479602230...
-
Repository
(from [07567aea5f0c6f14a53f511ab4cc46201b669795]) Revert "Fixed number_with_precision rounding error [#6182 state:resolved]"
This reverts commit 006ec77e60163d57d655479602230672d98e0f10.
https://github.com/rails/rails/commit/07567aea5f0c6f14a53f511ab4cc4... -
Piotr Sarnacki
- Milestone cleared.
- State changed from resolved to open
- Assigned user set to Piotr Sarnacki
Awww... sorry guys, I accidently applied that to master and pushed with other fix. I've reverted it now, so it's still open.
Don: please let me know on your findings about that failing test.
-
Don Wilson
Good catch Piotr :)
In certain cases in Ruby 1.8, BigDecimal / Float = Float. So, I just had to convert the other side to a BigDecimal before the division.
Just a note, when I convert it to BigDecimal, I have a to_f before the to_s. This was necessary because in Ruby 1.9, many times it is not a Float already, it is a Rational. When you do to_s on a Rational it looks like this "(1/100)". Then, BigDecimal doesn't read it correctly and thinks that you meant 1.0 instead of 0.01.
I have attached a new patch.
-
Repository
- State changed from open to resolved
(from [177749b8bfdbdca7bd996d2370c306b23a88f338]) Fixed number_with_precision rounding error [#6182 state:resolved] https://github.com/rails/rails/commit/177749b8bfdbdca7bd996d2370c30...
-
Repository
(from [f71809f25761440cbec9463bbc082987c90a471b]) Fixed number_with_precision rounding error [#6182 state:resolved] https://github.com/rails/rails/commit/f71809f25761440cbec9463bbc082...
