diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-24 21:12:55 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-03-24 21:12:55 +0000 |
commit | 0e62c773f603f885743d52f44fb032290f809cae (patch) | |
tree | 542d823fc775423effed089d56d635f5d176704c /actionpack/lib/action_view/helpers | |
parent | c6f2af5c31577e25c6f6b9f17be18858200a8e13 (diff) | |
download | rails-0e62c773f603f885743d52f44fb032290f809cae.tar.gz rails-0e62c773f603f885743d52f44fb032290f809cae.tar.bz2 rails-0e62c773f603f885743d52f44fb032290f809cae.zip |
Fixed NumberHelper#number_with_precision to properly round in a way that works equally on Mac, Windows, Linux (closes #11409, #8275, #10090, #8027) [zhangyuanyi]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9086 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 4 |
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 fe40725402..120bb4cc1f 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -144,11 +144,11 @@ module ActionView # # ==== Examples # number_with_precision(111.2345) # => 111.235 - # number_with_precision(111.2345, 2) # => 111.24 + # number_with_precision(111.2345, 2) # => 111.23 # number_with_precision(13, 5) # => 13.00000 # number_with_precision(389.32314, 0) # => 389 def number_with_precision(number, precision=3) - "%01.#{precision}f" % number + "%01.#{precision}f" % ((Float(number) * (10 ** precision)).round.to_f / 10 ** precision) rescue number end |