1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix number_to_currency to use negative format when rounding 0.5

Previously this function would fail to apply the negative format
correctly if the value being rounded was 0.5 exactly (modulo
precision).

This fixes the logic to use `>= 0.5` instead of `> 0.5`
This commit is contained in:
Mike Dalessio 2021-06-23 12:47:42 -04:00
parent 9a05443d1e
commit 8489a5e114
No known key found for this signature in database
GPG key ID: 59D3039C71577DD7
2 changed files with 2 additions and 1 deletions

View file

@ -19,7 +19,7 @@ module ActiveSupport
format = options[:negative_format]
else
number_f *= 10**options[:precision]
format = options[:negative_format] if number_f > 0.5
format = options[:negative_format] if number_f >= 0.5
end
end

View file

@ -81,6 +81,7 @@ module ActiveSupport
assert_equal("$0", number_helper.number_to_currency(-0.456789, precision: 0))
assert_equal("$0.0", number_helper.number_to_currency(-0.0456789, precision: 1))
assert_equal("$0.00", number_helper.number_to_currency(-0.00456789, precision: 2))
assert_equal("-$1", number_helper.number_to_currency(-0.5, precision: 0))
assert_equal("$1,11", number_helper.number_to_currency("1,11"))
assert_equal("$0,11", number_helper.number_to_currency("0,11"))
assert_equal("$,11", number_helper.number_to_currency(",11"))