aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/number_helper
diff options
context:
space:
mode:
authorMax Jacobson <max@hardscrabble.net>2015-07-14 00:54:56 -0400
committerMax Jacobson <max@hardscrabble.net>2015-07-26 12:37:39 -0400
commit597a9276671f5d7884a0ee1a617656dd5ee4b0ea (patch)
tree81b769002b81c4c926b52664d5d7b7a28cc995bc /activesupport/lib/active_support/number_helper
parente90b58106d09af585e85238d7d49cf79f006d4d4 (diff)
downloadrails-597a9276671f5d7884a0ee1a617656dd5ee4b0ea.tar.gz
rails-597a9276671f5d7884a0ee1a617656dd5ee4b0ea.tar.bz2
rails-597a9276671f5d7884a0ee1a617656dd5ee4b0ea.zip
Round some numbers more humanely
Fix #20869
Diffstat (limited to 'activesupport/lib/active_support/number_helper')
-rw-r--r--activesupport/lib/active_support/number_helper/number_to_human_converter.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb
index 5c6fe2df83..7a1f8171c0 100644
--- a/activesupport/lib/active_support/number_helper/number_to_human_converter.rb
+++ b/activesupport/lib/active_support/number_helper/number_to_human_converter.rb
@@ -20,9 +20,11 @@ module ActiveSupport
exponent = calculate_exponent(units)
@number = number / (10 ** exponent)
+ until (rounded_number = NumberToRoundedConverter.convert(number, options)) != NumberToRoundedConverter.convert(1000, options)
+ @number = number / 1000.0
+ exponent += 3
+ end
unit = determine_unit(units, exponent)
-
- rounded_number = NumberToRoundedConverter.convert(number, options)
format.gsub('%n'.freeze, rounded_number).gsub('%u'.freeze, unit).strip
end