mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
number_to_currency negative zero fix
This commit is contained in:
parent
76bafb0b2f
commit
92fea7a574
4 changed files with 11 additions and 1 deletions
|
@ -114,6 +114,8 @@ module ActionView
|
||||||
#
|
#
|
||||||
# number_to_currency("123a456", raise: true) # => InvalidNumberError
|
# number_to_currency("123a456", raise: true) # => InvalidNumberError
|
||||||
#
|
#
|
||||||
|
# number_to_currency(-0.456789, precision: 0)
|
||||||
|
# # => "$0"
|
||||||
# number_to_currency(-1234567890.50, negative_format: "(%u%n)")
|
# number_to_currency(-1234567890.50, negative_format: "(%u%n)")
|
||||||
# # => ($1,234,567,890.50)
|
# # => ($1,234,567,890.50)
|
||||||
# number_to_currency(1234567890.50, unit: "R$", separator: ",", delimiter: "")
|
# number_to_currency(1234567890.50, unit: "R$", separator: ",", delimiter: "")
|
||||||
|
|
|
@ -97,6 +97,10 @@ module ActiveSupport
|
||||||
# number_to_currency(1234567890.506, locale: :fr) # => "1 234 567 890,51 €"
|
# number_to_currency(1234567890.506, locale: :fr) # => "1 234 567 890,51 €"
|
||||||
# number_to_currency('123a456') # => "$123a456"
|
# number_to_currency('123a456') # => "$123a456"
|
||||||
#
|
#
|
||||||
|
# number_to_currency("123a456", raise: true) # => InvalidNumberError
|
||||||
|
#
|
||||||
|
# number_to_currency(-0.456789, precision: 0)
|
||||||
|
# # => "$0"
|
||||||
# number_to_currency(-1234567890.50, negative_format: '(%u%n)')
|
# number_to_currency(-1234567890.50, negative_format: '(%u%n)')
|
||||||
# # => "($1,234,567,890.50)"
|
# # => "($1,234,567,890.50)"
|
||||||
# number_to_currency(1234567890.50, unit: '£', separator: ',', delimiter: '')
|
# number_to_currency(1234567890.50, unit: '£', separator: ',', delimiter: '')
|
||||||
|
|
|
@ -12,8 +12,11 @@ module ActiveSupport
|
||||||
format = options[:format]
|
format = options[:format]
|
||||||
|
|
||||||
if number.to_f.negative?
|
if number.to_f.negative?
|
||||||
format = options[:negative_format]
|
|
||||||
number = absolute_value(number)
|
number = absolute_value(number)
|
||||||
|
|
||||||
|
unless options[:precision] == 0 && number.to_f < 0.5
|
||||||
|
format = options[:negative_format]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
rounded_number = NumberToRoundedConverter.convert(number, options)
|
rounded_number = NumberToRoundedConverter.convert(number, options)
|
||||||
|
|
|
@ -77,6 +77,7 @@ module ActiveSupport
|
||||||
assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", unit: "Kč", format: "%n %u"))
|
assert_equal("1,234,567,890.50 Kč", number_helper.number_to_currency("1234567890.50", unit: "Kč", format: "%n %u"))
|
||||||
assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", unit: "Kč", format: "%n %u", negative_format: "%n - %u"))
|
assert_equal("1,234,567,890.50 - Kč", number_helper.number_to_currency("-1234567890.50", unit: "Kč", format: "%n %u", negative_format: "%n - %u"))
|
||||||
assert_equal("0.00", number_helper.number_to_currency(+0.0, unit: "", negative_format: "(%n)"))
|
assert_equal("0.00", number_helper.number_to_currency(+0.0, unit: "", negative_format: "(%n)"))
|
||||||
|
assert_equal("$0", number_helper.number_to_currency(-0.456789, precision: 0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue