medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.23k stars 2.66k forks source link

zero-decimal currencies are beeing divided by 100 #5932

Closed Dalvae closed 11 months ago

Dalvae commented 11 months ago

Bug report

We are encountering an issue where Chilean Pesos (CLP) prices are being processed as decimal-based currencies in our application. As a zero-decimal currency, CLP should not be divided by 100, but currently, all CLP amounts are being treated this way, leading to incorrect price calculations and display. System information

Medusa version (including plugins): [1.18.1]
Node.js version: [Node.js 17]
Database: [postresql]
Operating system: [ubuntu.server]

Steps to reproduce the behavior

Set the application currency to CLP.
Input or retrieve a product price, for example, 1000 CLP.
Observe that the price is being processed and displayed as 10 CLP, indicating an incorrect division by 100.

Expected behavior

For zero-decimal currencies like CLP, the amount should be treated as the smallest currency unit without conversion. Therefore, a price of 1000 CLP should be processed and displayed exactly as 1000 CLP, without being divided by 100.

Screenshots

frontend display json response

This is the helper function, thanks to @VariableVic

olivermrbl commented 11 months ago

Our Next.js starter uses our medusa-react to convert raw prices to a human-readable amount. Right now, it uses a hardcoded list of no-division currencies. We are aware that this is a sub-optimal way of handling it, but it's what we have to work with for now.

I am happy to accept a PR adding CLP to the list. Alternatively, you can use our utils in medusa-react to handle the price displaying yourself following a similar approach as to what we do.

Update: I realise you are aware of the hardcoded list already. Let me know how you want to proceed from here, and I can help :)