diff options
author | Travis Briggs <briggs.travis@gmail.com> | 2009-03-18 21:51:26 -0400 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-05-17 19:02:50 +0200 |
commit | 98eaa2c6834e418959f2a1a18421e4811167e03b (patch) | |
tree | 572e6d9cf43af56feb7e28b94f8711d99b61ecbd /actionpack/lib | |
parent | e41984c5f7f38b62c05dfcb54940bf51f6961aeb (diff) | |
download | rails-98eaa2c6834e418959f2a1a18421e4811167e03b.tar.gz rails-98eaa2c6834e418959f2a1a18421e4811167e03b.tar.bz2 rails-98eaa2c6834e418959f2a1a18421e4811167e03b.zip |
Ensure number_to_human_size does not strip zeros from the end [#1763 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index c02692b09a..999d5b34fc 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -248,6 +248,11 @@ module ActionView # number_to_human_size(483989, :precision => 0) # => 473 KB # number_to_human_size(1234567, :precision => 2, :separator => ',') # => 1,18 MB # + # Zeros after the decimal point are always stripped out, regardless of the + # specified precision: + # helper.number_to_human_size(1234567890123, :precision => 5) # => "1.12283 TB" + # helper.number_to_human_size(524288000, :precision=>5) # => "500 MB" + # # You can still use <tt>number_to_human_size</tt> with the old API that accepts the # +precision+ as its optional second parameter: # number_to_human_size(1234567, 2) # => 1.18 MB @@ -293,7 +298,7 @@ module ActionView :precision => precision, :separator => separator, :delimiter => delimiter - ).sub(/(\d)(#{escaped_separator}[1-9]*)?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '') + ).sub(/(#{escaped_separator})(\d*[1-9])?0+\z/, '\1\2').sub(/#{escaped_separator}\z/, '') storage_units_format.gsub(/%n/, formatted_number).gsub(/%u/, unit) rescue number |