diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-24 13:00:01 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-04-24 13:00:01 -0700 |
commit | 6f405df2c0ba22b30b6d52028e467aa5bee59429 (patch) | |
tree | 5cea16cfa4fa18cd622770510c11561e43e7eb53 | |
parent | a64894dac881d398409cba12d259083dd18a9b27 (diff) | |
parent | e772daad20e865297f1907815b44f83de6f41f46 (diff) | |
download | rails-6f405df2c0ba22b30b6d52028e467aa5bee59429.tar.gz rails-6f405df2c0ba22b30b6d52028e467aa5bee59429.tar.bz2 rails-6f405df2c0ba22b30b6d52028e467aa5bee59429.zip |
Merge pull request #10332 from vipulnsward/number_helper
refactor number helper
-rw-r--r-- | activesupport/lib/active_support/number_helper.rb | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb index cc935e6cb9..414960d2b1 100644 --- a/activesupport/lib/active_support/number_helper.rb +++ b/activesupport/lib/active_support/number_helper.rb @@ -295,7 +295,7 @@ module ActiveSupport options = format_options(options[:locale]).merge!(options) - parts = number.to_s.to_str.split('.') + parts = number.to_s.split('.') parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}") parts.join(options[:separator]) end @@ -356,7 +356,8 @@ module ActiveSupport digits, rounded_number = 1, 0 else digits = (Math.log10(number.abs) + 1).floor - rounded_number = (BigDecimal.new(number.to_s) / BigDecimal.new((10 ** (digits - precision)).to_f.to_s)).round.to_f * 10 ** (digits - precision) + multiplier = 10 ** (digits - precision) + rounded_number = (BigDecimal.new(number.to_s) / BigDecimal.new(multiplier.to_f.to_s)).round.to_f * multiplier digits = (Math.log10(rounded_number.abs) + 1).floor # After rounding, the number of digits may have changed end precision -= digits |