Skip to content

Commit

Permalink
Fix number_to_human_size incorrectly removing trailing zeros. Closes #…
Browse files Browse the repository at this point in the history
…10099 [libc, developingchris]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8774 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Feb 2, 2008
1 parent b84a33d commit 9d79e06
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.terabyte; "%.#{precision}f GB" % (size / 1.0.gigabyte)
else "%.#{precision}f TB" % (size / 1.0.terabyte)
end.sub(/([0-9])\.?0+ /, '\1 ' )
end.sub(/([0-9]\.\d*?)0+ /, '\1 ' ).sub(/\. /,' ')
rescue
nil
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 '10 KB', number_to_human_size(10.000.kilobytes, 4)
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(nil)
end
Expand Down

0 comments on commit 9d79e06

Please sign in to comment.