RubyMoney / money

A Ruby Library for dealing with money and currency conversion.
http://rubymoney.github.io/money
MIT License
2.72k stars 621 forks source link

The Swedish Krona's sub-unit is displayed #933

Closed akhtarja closed 4 years ago

akhtarja commented 4 years ago

We are using this gem for a large SaaS with customers all over the world. A client in Sweden pointed out that we are displaying the sub-unit of the Swedish Krona (SEK) in prices.

The Swedish Krona's sub-unit is not conventionally used in Sweden, and prices are, as a general rule, always shown in whole Krona.

Expected behaviour: Amounts in SEK should be returned as whole numbers. This could follow the same pattern as the Icelandic Krona, which also has a sub-unit that isn't conventionally used. Both currencies don't have banknotes or coins in denominations of less than 1 krona.

This change would need to handle for existing implementations, as simply mimicing the Icelandic Krona pattern results in the numbers returned being inflated (i.e. 1.00 kr becomes 100 kr) - a breaking change.

ct-clearhaus commented 4 years ago

From a Dane that only seldomly visits Sweden, the use of sub-unit seems to depend on the context:

The last minor unit coin, the "50 ΓΆre", became invalid as of 2010-10-01. Old habits die hard.

In Denmark it is also quite normal to see prices like 89.99 DKK although the 0.01 DKK coin died in 1973; if you buy 50 items that cost 0.99 each and pay with cash, you'll pay 49.50 as we still have the 0.50 coin, if you pay by card, you will pay with sub-unit precision without any rounding. I would be surprised if it's any different on the other side of the bridge πŸ™‚

In April, 9.9 % of the x*10^5 e-commerce payments in SEK made via our systems did have an amount not ending with 00 πŸ™‚

Referring to https://github.com/RubyMoney/money/pull/742#issuecomment-357890506, I'll expect SEK to have exponent 2 since it'll be in accordance with ISO 4217 πŸ™‚

akhtarja commented 4 years ago

Thank you for the thorough explanation @ct-clearhaus - this makes sense, and I think it would be improper to change the library's behaviour on this to accommodate our customers specifically. I'll talk this through with our product team, and if necessary, we'll fork the library and make the changes there, just for our own use.

ct-clearhaus commented 4 years ago

Visa and Mastercard does also not follow ISO 4217, so we have locally overridden some exponent values; that's easily possible without forking the library πŸ™‚

overrides = {
  isk: { subunit_to_unit: 100 },
  sek: { subunit_to_unit: 1 },
}

overrides.each do |key, config|
  Money::Currency.register(Money::Currency.table[key].to_h.merge(config))
end