Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Number of Decimals in USDC Currency #1081

Closed
brent-cybrid opened this issue Mar 5, 2024 · 9 comments · Fixed by #1089
Closed

Incorrect Number of Decimals in USDC Currency #1081

brent-cybrid opened this issue Mar 5, 2024 · 9 comments · Fixed by #1089

Comments

@brent-cybrid
Copy link

In config/currency_non_iso.json, the currency configuration for usdc is configured for "subunit_to_unit": 100, however, USDC supports six decimal places of precision, not 2.

The configuration for usdc should show "subunit_to_unit": 1000000.

@tagliala
Copy link
Contributor

tagliala commented Mar 8, 2024

Hi, it is pretty clear that USDC has 6 decimal places, but is there an official reference?
Also, I guess the subunit definition is also wrong should not be Cent anymore after this change

@stebo
Copy link

stebo commented Mar 11, 2024

The official reference would probably be to check the decimals() on the USDC contract, depending on the chain you are on, e.g. USDC on Ethereum: https://etherscan.io/token/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#readProxyContract

-> decimals = 6

--

Another related question: If I'd save USDC with "subunit_to_unit": 1000000
then Money.from_cents(2345678, "USDC") => 2.345678 USDC

How can I now use .format to only display a rounded 2 decimals? => 2.35 USDC
Any way to do this and define precision on format?

@tagliala
Copy link
Contributor

What about the subunit name? I guess that cents would not apply anymore since they are not cents anymore. BTC are using Satoshis as subunit name

@stebo
Copy link

stebo commented Mar 12, 2024

What about the subunit name? I guess that cents would not apply anymore since they are not cents anymore. BTC are using Satoshis as subunit name

You can change the migrations and just use whatever column name suits your case better then _cents
monetize :prize_satoshis

I usually just continue using _cents, although I have BTC, ETH & other crypto coins (which all have other subunit names). There is also probably a couple of fiat currencies that do not really have cents.

@semmons99
Copy link
Member

welcome a PR, to update this. just not something we actively monitor ourselves.

@tagliala
Copy link
Contributor

tagliala commented Mar 13, 2024

I can work on this (at the end of next week), can you please reopen for tracking purposes?

@semmons99
Copy link
Member

Sure. Done.

@semmons99 semmons99 reopened this Mar 13, 2024
@semmons99
Copy link
Member

checking in on status

@tagliala
Copy link
Contributor

Confirm that I will have time during this weekend

tagliala added a commit to tagliala/money that referenced this issue Mar 21, 2024
tagliala added a commit to tagliala/money that referenced this issue Mar 21, 2024
This fix can introduce a breaking change

Before:
```
Money.new(100, "USDC").to_s
 => "1.00"
```


After:
```
Money.new(100, "USDC").to_s
 => "0.000100" 
```

Close RubyMoney#1081
tagliala added a commit to tagliala/money that referenced this issue Mar 22, 2024
This fix can introduce a breaking change

Before:
```
Money.new(100, "USDC").to_s
 => "1.00"
```


After:
```
Money.new(100, "USDC").to_s
 => "0.000100" 
```

Close RubyMoney#1081
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants