diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-13 04:49:01 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-13 04:49:01 +0000 |
commit | 988dc1e8624ab429537006d9cf86008e8b9eedd0 (patch) | |
tree | e3da446f699e0c86356f84ae324f76aa97c7f7ef /actionpack/lib | |
parent | 5fe0ecce0afd86a3ad244ca829deee92950476b2 (diff) | |
download | rails-988dc1e8624ab429537006d9cf86008e8b9eedd0.tar.gz rails-988dc1e8624ab429537006d9cf86008e8b9eedd0.tar.bz2 rails-988dc1e8624ab429537006d9cf86008e8b9eedd0.zip |
Improved tests for NumberHelper
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1151 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/number_helper.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 2f753558b2..e90d812384 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -35,13 +35,13 @@ module ActionView # Examples: # number_to_currency(1234567890.50) => $1,234,567,890.50 # number_to_currency(1234567890.506) => $1,234,567,890.51 - # number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""}) => £123456789,50 + # number_to_currency(1234567890.50, {:unit => "£", :separator => ",", :delimiter => ""}) => £1234567890,50 def number_to_currency(number, options = {}) options = options.stringify_keys precision, unit, separator, delimiter = options.delete("precision") { 2 }, options.delete("unit") { "$" }, options.delete("separator") { "." }, options.delete("delimiter") { "," } begin parts = number_with_precision(number, precision).split('.') - unit + number_with_delimiter(parts[0]) + separator + parts[1].to_s + unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].to_s rescue number end @@ -72,9 +72,9 @@ module ActionView # Formats a +number+ with a +delimiter+. # Example: - # number_with_delimiter(12345678) => 1,235,678 + # number_with_delimiter(12345678) => 12,345,678 def number_with_delimiter(number, delimiter=",") - number.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}") + number.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}") end # Returns a formatted-for-humans file size. |