Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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 jeremy authored
View
2  actionpack/lib/action_view/helpers/number_helper.rb
@@ -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
View
1  actionpack/test/template/number_helper_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.