aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-08-05 01:00:54 +0000
committerMichael Koziarski <michael@koziarski.com>2007-08-05 01:00:54 +0000
commitab5e1f15a67b22410835a84ba11a926f50b31cbe (patch)
treeeefac0c80de82101f9e2ec2606afb8ca8adad291 /actionpack/lib/action_view/helpers
parentc4c6662498cb85feb407ccb86d8694e38f439f31 (diff)
downloadrails-ab5e1f15a67b22410835a84ba11a926f50b31cbe.tar.gz
rails-ab5e1f15a67b22410835a84ba11a926f50b31cbe.tar.bz2
rails-ab5e1f15a67b22410835a84ba11a926f50b31cbe.zip
Fix number_to_human_size when using different precisions. Closes #7536. [RichardStrand, mpalmer]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7275 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index e2db853f93..64e424df2f 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -164,13 +164,13 @@ module ActionView
def number_to_human_size(size, precision=1)
size = Kernel.Float(size)
case
- when size == 1 : "1 Byte"
+ when size.to_i == 1 : "1 Byte"
when size < 1.kilobyte: "%d Bytes" % size
when size < 1.megabyte: "%.#{precision}f KB" % (size / 1.0.kilobyte)
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', '')
+ end.sub(/([0-9])\.?0+ /, '\1 ' )
rescue
nil
end