vendure-ecommerce / vendure

The commerce platform with customization in its DNA.
https://www.vendure.io
Other
5.78k stars 1.03k forks source link

Some currencies don't use sub-units in practice #1511

Closed giovramirez closed 2 years ago

giovramirez commented 2 years ago

Is your feature request related to a problem? Please describe.

I set currency to COP on the Admin UI and the returned price from the shop-api shows it with two extra zeros.

Expected value: 109900 Returned value: 10990000

image

For Colombian Pesos, the item's price are usually displayed as '$ 10.900', '$ 110.000' or '$ 1.200.000'.

We do have 'Centavos' as a subunit, however, it is not used in practice, since it could not be paid in cash with it.

Describe the solution you'd like

For now we can remove the extra zeros before to display the price on the store front, right? But it would be great if we can handle it from the Vendure core.

michaelbromley commented 2 years ago

This relates to #1146 - which was closed when I implemented a solution (https://github.com/vendure-ecommerce/vendure/commit/fd643b30f7203295bb6ed29da04dc9ce0c284c62) which uses the Intl API to check whether the given currency has a "fractional" part.

The issue seems to be that the implementation currently does not take into account whether the fractional part is used "in practice". So for example with JPY (Japanese Yen) there is literally no fractional part, so the display is always an integer.

For COP, there is a fractional part, so we need to see if there is some way to discern whether a fractional part is used "in practice" - maybe this data is available in the Intl API or maybe we need to supply this data in a hard-coded way. Needs investigation.

michaelbromley commented 2 years ago

Reference: https://simple.wikipedia.org/wiki/Colombian_peso

The peso is divided into 100 centavos. However, because the value of Colombia’s currency is extremely low. Although 1 centavo and 5 centavo coins still exist, the lowest denomination of the Colombian peso that is commonly used is the 50 pesos coin.

This is a tough one to solve because the Intl API only deals with the official specification. Specifically, ISO 4217 defines the "exponent" used by each currency (how many digits after the decimal point), which indeed lists COP as 2.

So perhaps the solution here is to maintain an "unofficial" list of modifications to ISO 4217 where we can override that exponent and e.g. force COP to 0.

My question is - which other currencies are in this situation? I'd ideally like a somewhat authoritative list of currencies where the "real-world" use of minor units differs from the ISO 4217 spec. We could then hard-code this into the Admin UI currency formatting logic.

Looking at some other payment providers, they all seem to just use ISO 4217 as-is.

giovramirez commented 2 years ago

We can just keep it as it is now (the standard way) and remove the sub-unit on the store front side which is essentially what I am doing.

Unless there are some other currencies with this need out there, there is no need in going for a hard-code list.

Thanks @michaelbromley for taking a look at this!

michaelbromley commented 2 years ago

OK, in that case I'll close this issue and maybe if over time others comment that other currencies fall into this category too, we can re-visit.

kartikjethani-solidity commented 3 months ago

we're facing the same issue with currency in INR (Indian Rupee)

michaelbromley commented 3 months ago

@kartikjethani-solidity you mean INR is normally used without exponent in real-world situations?