Skip to content

Commit

Permalink
Merge r8774 from trunk: fix number_to_human_size incorrectly removing…
Browse files Browse the repository at this point in the history
… trailing zeros. References #10099.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/2-0-stable@8775 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Feb 2, 2008
1 parent 6997918 commit f09a529
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/number_helper.rb
Expand Up @@ -170,7 +170,7 @@ def number_to_human_size(size, precision=1)
when size < 1.gigabyte; "%.#{precision}f MB" % (size / 1.0.megabyte) when size < 1.gigabyte; "%.#{precision}f MB" % (size / 1.0.megabyte)
when size < 1.terabyte; "%.#{precision}f GB" % (size / 1.0.gigabyte) when size < 1.terabyte; "%.#{precision}f GB" % (size / 1.0.gigabyte)
else "%.#{precision}f TB" % (size / 1.0.terabyte) else "%.#{precision}f TB" % (size / 1.0.terabyte)
end.sub(/([0-9])\.?0+ /, '\1 ' ) end.sub(/([0-9]\.\d*?)0+ /, '\1 ' ).sub(/\. /,' ')
rescue rescue
nil nil
end end
Expand Down
1 change: 1 addition & 0 deletions actionpack/test/template/number_helper_test.rb
Expand Up @@ -87,6 +87,7 @@ def test_number_to_human_size
assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4) assert_equal '1.01 KB', number_to_human_size(1.0100.kilobytes, 4)
assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4) assert_equal '10 KB', number_to_human_size(10.000.kilobytes, 4)
assert_equal '1 Byte', number_to_human_size(1.1) assert_equal '1 Byte', number_to_human_size(1.1)
assert_equal '10 Bytes', number_to_human_size(10)
assert_nil number_to_human_size('x') assert_nil number_to_human_size('x')
assert_nil number_to_human_size(nil) assert_nil number_to_human_size(nil)
end end
Expand Down

0 comments on commit f09a529

Please sign in to comment.