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

Change decimal numbers handle on the backend #245

Open
letehaha opened this issue Aug 31, 2023 · 0 comments
Open

Change decimal numbers handle on the backend #245

letehaha opened this issue Aug 31, 2023 · 0 comments
Labels
crypto Crypto features need more info Requires additional details priority-3-low repo: backend Related to back-end repo: frontend Related to front-end type::enhancement New feature or request

Comments

@letehaha
Copy link
Owner

letehaha commented Aug 31, 2023

Right now we multiply amounts by 100. It's already a problem since we need to multiply currency rates by at least 10,000. Also, it is difficult to maintain since you need to not forget to do multiplications each time.

Need to switch to using decimal.js and store raw decimal values in the DB as strings (or decimals, still TBD).

Pros:
– no need to care about multiply/divide logic, you can just work with raw values and return them to the client (so client will be simplified as well)
– DB will have readable values format
– if there's a need to add crypto support, or etc, it will require zero effort, but only updation to decimal.js config.

Cons:
– DB size will be increased compared to storing raw integers
– not able to make arithmetical operations directly in the SQL queries (currently we do that only in a single place)
– read/create/update operations in the DB require transformation from number to string and vice versa


TBD:

  1. What data format return to client – number or string
  2. What data format use to store in the DB – decimal number or string. Since we will still need to transform data in the DB => Model layer, there's no much difference in what format we need to store it. So in that case decimal might be better, since we will be able to make arithmetic operations with SQL queries in urgent cases (because we need to aim to make these calculations using JS in the services anyway).
@letehaha letehaha added type::enhancement New feature or request repo: frontend Related to front-end repo: backend Related to back-end crypto Crypto features need more info Requires additional details priority-1-high High priority labels Aug 31, 2023
@letehaha letehaha added priority-3-low and removed priority-1-high High priority labels Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crypto Crypto features need more info Requires additional details priority-3-low repo: backend Related to back-end repo: frontend Related to front-end type::enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant