Permalink
Browse files

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
  • Loading branch information...
1 parent 3004217 commit afbfde9357ab0c6bbaebb62eaa99af8c3825d6ac @dhh dhh committed Sep 9, 2005
View
@@ -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">
@@ -37,6 +37,7 @@ def number_to_phone(number, options = {})
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
@@ -18,6 +18,8 @@ def test_number_to_phone
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

0 comments on commit afbfde9

Please sign in to comment.