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:
parent
9a05443d1e
commit
8489a5e114
2 changed files with 2 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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"))
|
||||
|
|
Loading…
Reference in a new issue