aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-09 08:43:02 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-09 08:43:02 +0000
commitafbfde9357ab0c6bbaebb62eaa99af8c3825d6ac (patch)
tree19f526f27d68af511d9e4abf25a044bd7228901f
parent300421785532b78f719a241843206e210bb7cc9d (diff)
downloadrails-afbfde9357ab0c6bbaebb62eaa99af8c3825d6ac.tar.gz
rails-afbfde9357ab0c6bbaebb62eaa99af8c3825d6ac.tar.bz2
rails-afbfde9357ab0c6bbaebb62eaa99af8c3825d6ac.zip
Fixed that number_to_currency(1000, {:precision => 0})) should return "$1,000", instead of "$1,000." #2122 [sd@notso.net]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2170 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/number_helper.rb1
-rw-r--r--actionpack/test/template/number_helper_test.rb2
3 files changed, 5 insertions, 0 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 6bb633ed2d..e38c743506 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that number_to_currency(1000, {:precision => 0})) should return "$1,000", instead of "$1,000." #2122 [sd@notso.net]
+
* Allow link_to_remote to use any DOM-element as the parent of the form elements to be submitted #2137 [erik@ruby-lang.nl]. Example:
<tr id="row023">
diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb
index b1757c864c..6c66616e1a 100644
--- a/actionpack/lib/action_view/helpers/number_helper.rb
+++ b/actionpack/lib/action_view/helpers/number_helper.rb
@@ -37,6 +37,7 @@ module ActionView
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") { "," }
+ separator = "" unless precision > 0
begin
parts = number_with_precision(number, precision).split('.')
unit + number_with_delimiter(parts[0], delimiter) + separator + parts[1].to_s
diff --git a/actionpack/test/template/number_helper_test.rb b/actionpack/test/template/number_helper_test.rb
index 3c214b76e5..b0debc44fa 100644
--- a/actionpack/test/template/number_helper_test.rb
+++ b/actionpack/test/template/number_helper_test.rb
@@ -18,6 +18,8 @@ class NumberHelperTest < Test::Unit::TestCase
def test_number_to_currency
assert_equal("$1,234,567,890.50", number_to_currency(1234567890.50))
assert_equal("$1,234,567,890.51", number_to_currency(1234567890.506))
+ assert_equal("$1,234,567,890", number_to_currency(1234567890.50, {:precision => 0}))
+ assert_equal("$1,234,567,890.5", number_to_currency(1234567890.50, {:precision => 1}))
assert_equal("&pound;1234567890,50", number_to_currency(1234567890.50, {:unit => "&pound;", :separator => ",", :delimiter => ""}))
end