diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-12-17 16:11:47 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-12-17 16:11:47 +0100 |
commit | 07567aea5f0c6f14a53f511ab4cc46201b669795 (patch) | |
tree | e3c8f723feeab923efc55d714167dde1df134d25 /actionpack/lib | |
parent | f7e33620caffecb7f065c5e4f5a19597f8c35cdd (diff) | |
download | rails-07567aea5f0c6f14a53f511ab4cc46201b669795.tar.gz rails-07567aea5f0c6f14a53f511ab4cc46201b669795.tar.bz2 rails-07567aea5f0c6f14a53f511ab4cc46201b669795.zip |
Revert "Fixed number_with_precision rounding error [#6182 state:resolved]"
This reverts commit 006ec77e60163d57d655479602230672d98e0f10.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 650828052f..a9400c347f 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -270,13 +270,12 @@ module ActionView digits, rounded_number = 1, 0 else digits = (Math.log10(number.abs) + 1).floor - rounded_number = (BigDecimal.new(number.to_s) / 10 ** (digits - precision)).round.to_f * 10 ** (digits - precision) - digits = (Math.log10(rounded_number.abs) + 1).floor # After rounding, the number of digits may have changed + rounded_number = BigDecimal.new((number / 10 ** (digits - precision)).to_s).round.to_f * 10 ** (digits - precision) end precision -= digits precision = precision > 0 ? precision : 0 #don't let it be negative else - rounded_number = BigDecimal.new(number.to_s).round(precision).to_f + rounded_number = BigDecimal.new((number * (10 ** precision)).to_s).round.to_f / 10 ** precision end formatted_number = number_with_delimiter("%01.#{precision}f" % rounded_number, options) if strip_insignificant_zeros |