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

[Question] Is it possible to use the library to handle substraction and addition of different subdivisions of the same coin ? #763

Open
p4535992 opened this issue Nov 7, 2023 · 0 comments

Comments

@p4535992
Copy link

p4535992 commented Nov 7, 2023

I start with the fact that I do not know if the library is designed to handle this use case, I ask just in case.

Is it possible to use the library to handle substraction and addition of different subdivisions. of the same coin ?

I read the API documentation: https://v2.dinerojs.com/docs/core-concepts/currency, and the british pound example, but i have still some doubt.

Let me explain better with an example my coin is "Coin" , but with three formats "TCoin" for thousands , "HCoin" for hundreds , "DCoin" for tens and "Coin" for as base coin.

So the map would be:

1 TCoin = 10 HCoin = 100 DCoin = 1000 Coin
1 HCoin = 10 Dcoin = 100 Coin
1 DCoin = 10 Coin

So i can map a currency like this ?

const TCOIN = {
  code: 'TCOIN',
  base: [1000],
  exponent: 1,
};

const HCOIN = {
  code: 'HCOIN',
  base: [100],
  exponent: 1,
};

const DCOIN = {
  code: 'DCOIN',
  base: [10],
  exponent: 1,
};

const COIN = {
  code: 'COIN',
  base: [1],
  exponent: 1,
};

is this right (not sure about this)? At this point, however, I get lost.

My goal is to try to have this mechanism for my wallet.

Wallet = 30 TCoin 20 HCoin 5 DCoin  35 Coin

Substract 10 DCoin

Wallet = 30 TCoin 19 HCoin 5 DCoin  35 Coin

Substract 5 DCoin

Wallet = 30 TCoin 19 HCoin 0 DCoin  35 Coin

Add 9 DCoin

Wallet = 30 TCoin 19 HCoin 9 DCoin  35 Coin

Add 10 DCoin

Wallet = 30 TCoin 20 HCoin 9 DCoin  35 Coin


@p4535992 p4535992 changed the title [Question] Is it possible to use the library to handle substraction and addition of different subdivisions. of the same coin ? [Question] Is it possible to use the library to handle substraction and addition of different subdivisions of the same coin ? Nov 7, 2023
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

No branches or pull requests

1 participant