Skip to content
This repository
Browse code

Fix number_to_human_size incorrectly removing trailing zeros. Closes #…

…10099 [libc, developingchris]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8774 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 9d79e0668d6a51573170ee568c5bac6717ec1a0c 1 parent b84a33d
Jeremy Kemper authored February 02, 2008
2  actionpack/lib/action_view/helpers/number_helper.rb
@@ -170,7 +170,7 @@ def number_to_human_size(size, precision=1)
170 170
           when size < 1.gigabyte; "%.#{precision}f MB"  % (size / 1.0.megabyte)
171 171
           when size < 1.terabyte; "%.#{precision}f GB"  % (size / 1.0.gigabyte)
172 172
           else                    "%.#{precision}f TB"  % (size / 1.0.terabyte)
173  
-        end.sub(/([0-9])\.?0+ /, '\1 ' )
  173
+        end.sub(/([0-9]\.\d*?)0+ /, '\1 ' ).sub(/\. /,' ')
174 174
       rescue
175 175
         nil
176 176
       end
1  actionpack/test/template/number_helper_test.rb
@@ -87,6 +87,7 @@ def test_number_to_human_size
87 87
     assert_equal '1.01 KB',   number_to_human_size(1.0100.kilobytes, 4)
88 88
     assert_equal '10 KB',   number_to_human_size(10.000.kilobytes, 4)
89 89
     assert_equal '1 Byte',   number_to_human_size(1.1)
  90
+    assert_equal '10 Bytes', number_to_human_size(10)
90 91
     assert_nil number_to_human_size('x')
91 92
     assert_nil number_to_human_size(nil)
92 93
   end

0 notes on commit 9d79e06

Please sign in to comment.
Something went wrong with that request. Please try again.