diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-09 00:59:19 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-10-09 00:59:19 +0000 |
commit | a49e7d5c0c5dc9f48d7c0b5a620d1528d998accc (patch) | |
tree | 6940639fad9dba18af32612b03c01590e6747410 /actionpack/lib/action_view | |
parent | f9650a23f060c0d8678b2bda45e502f0bca487cc (diff) | |
download | rails-a49e7d5c0c5dc9f48d7c0b5a620d1528d998accc.tar.gz rails-a49e7d5c0c5dc9f48d7c0b5a620d1528d998accc.tar.bz2 rails-a49e7d5c0c5dc9f48d7c0b5a620d1528d998accc.zip |
Fixed that NumberHelper#number_to_delimiter should respect precision of higher than two digits (closes #6231) [phallstrom]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5249 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index cb312320ef..1c9912f877 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -71,10 +71,16 @@ module ActionView # Formats a +number+ with a +delimiter+. # Example: # number_with_delimiter(12345678) => 12,345,678 - def number_with_delimiter(number, delimiter=",") - number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}") + def number_with_delimiter(number, delimiter=",", separator=".") + begin + parts = number.to_s.split(separator) + parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}") + parts.join separator + rescue + number + end end - + # Returns a formatted-for-humans file size. # # Examples: |