diff options
author | Vipul A M <vipulnsward@gmail.com> | 2013-04-25 00:59:16 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2013-04-25 00:59:16 +0530 |
commit | e772daad20e865297f1907815b44f83de6f41f46 (patch) | |
tree | 7c9739b30eb3c3aee8fbfd5402dea4a2c58896ee | |
parent | 2a8994122588a2bafb8cf052f2ca1a49a2b758d6 (diff) | |
download | rails-e772daad20e865297f1907815b44f83de6f41f46.tar.gz rails-e772daad20e865297f1907815b44f83de6f41f46.tar.bz2 rails-e772daad20e865297f1907815b44f83de6f41f46.zip |
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 |