aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/number_helper.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-06 16:21:28 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2015-02-06 16:21:28 -0200
commit2d2bcde3cb80ee7d51dc3ad056dfe9d808a95389 (patch)
tree62b8ee2c11a47d553f5d58a8682913d377f87fdc /activesupport/lib/active_support/number_helper.rb
parent9c47b874d112414df7f80f9ed852adb48ba6d268 (diff)
parent24a7e609437d9e6ea61140492461631c4d5bd665 (diff)
downloadrails-2d2bcde3cb80ee7d51dc3ad056dfe9d808a95389.tar.gz
rails-2d2bcde3cb80ee7d51dc3ad056dfe9d808a95389.tar.bz2
rails-2d2bcde3cb80ee7d51dc3ad056dfe9d808a95389.zip
Merge pull request #12067 from jackxxu/keep_precision
Enable number_to_percentage to keep the number's precision by allowing :precision option value to be nil Conflicts: activesupport/CHANGELOG.md activesupport/lib/active_support/number_helper.rb activesupport/test/number_helper_test.rb
Diffstat (limited to 'activesupport/lib/active_support/number_helper.rb')
-rw-r--r--activesupport/lib/active_support/number_helper.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/number_helper.rb b/activesupport/lib/active_support/number_helper.rb
index 34439ee8be..cfca42bc69 100644
--- a/activesupport/lib/active_support/number_helper.rb
+++ b/activesupport/lib/active_support/number_helper.rb
@@ -94,7 +94,7 @@ module ActiveSupport
# * <tt>:locale</tt> - Sets the locale to be used for formatting
# (defaults to current locale).
# * <tt>:precision</tt> - Sets the precision of the number
- # (defaults to 3).
+ # (defaults to 3). Keeps the number's precision if nil.
# * <tt>:significant</tt> - If +true+, precision will be the #
# of significant_digits. If +false+, the # of fractional
# digits (defaults to +false+).
@@ -116,6 +116,7 @@ module ActiveSupport
# number_to_percentage(1000, delimiter: '.', separator: ',') # => 1.000,000%
# number_to_percentage(302.24398923423, precision: 5) # => 302.24399%
# number_to_percentage(1000, locale: :fr) # => 1 000,000%
+ # number_to_percentage:(1000, precision: nil) # => 1000%
# number_to_percentage('98a') # => 98a%
# number_to_percentage(100, format: '%n %') # => 100 %
def number_to_percentage(number, options = {})
@@ -161,7 +162,7 @@ module ActiveSupport
# * <tt>:locale</tt> - Sets the locale to be used for formatting
# (defaults to current locale).
# * <tt>:precision</tt> - Sets the precision of the number
- # (defaults to 3).
+ # (defaults to 3). Keeps the number's precision if nil.
# * <tt>:significant</tt> - If +true+, precision will be the #
# of significant_digits. If +false+, the # of fractional
# digits (defaults to +false+).
@@ -182,6 +183,7 @@ module ActiveSupport
# number_to_rounded(111.2345, significant: true) # => 111
# number_to_rounded(111.2345, precision: 1, significant: true) # => 100
# number_to_rounded(13, precision: 5, significant: true) # => 13.000
+ # number_to_rounded(13, precision: nil) # => 13
# number_to_rounded(111.234, locale: :fr) # => 111,234
#
# number_to_rounded(13, precision: 5, significant: true, strip_insignificant_zeros: true)