monetize icon indicating copy to clipboard operation
monetize copied to clipboard

parse_collection will always return default_currency if the string contains symbol

Open penghouho opened this issue 4 years ago • 1 comments

If the default_currency is configured, the Monetize.parse_collection won't return correct value with symbol (the currency is hardcoded to the default currency)

MoneyRails.configure do |config|
  config.default_currency = -> { 'MYR' }
end

# wrong
Monetize.parse_collection("€80, $100")
@list=[#<Money fractional:8000 currency:MYR>, #<Money fractional:10000 currency:MYR>],

# wrong at $100
Monetize.parse_collection("EUR80, $100")
@list=[#<Money fractional:8000 currency:EUR>, #<Money fractional:10000 currency:MYR>],

# correct
Monetize.parse_collection("EUR80, USD100")
@list=[#<Money fractional:8000 currency:EUR>, #<Money fractional:10000 currency:USD>],

penghouho avatar Feb 23 '21 08:02 penghouho

The symbol can be ambiguous—many currencies use $. Therefore, when an explicit default_currency is set, we override symbol parsing and use the default_currency unless an ISO currency is provided.

semmons99 avatar Mar 02 '21 19:03 semmons99