Permalink
Browse files

refactor number helper

  • Loading branch information...
vipulnsward committed Apr 24, 2013
1 parent 2a89941 commit e772daad20e865297f1907815b44f83de6f41f46
Showing with 3 additions and 2 deletions.
  1. +3 −2 activesupport/lib/active_support/number_helper.rb
@@ -295,7 +295,7 @@ def number_to_delimited(number, options = {})
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 @@ def number_to_rounded(number, options = {})
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

0 comments on commit e772daa

Please sign in to comment.