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

Decimals #56

Open
buckyroberts opened this issue Feb 8, 2021 · 1 comment
Open

Decimals #56

buckyroberts opened this issue Feb 8, 2021 · 1 comment
Assignees

Comments

@buckyroberts
Copy link
Collaborator

We would like to store the balances as integers (as we already do) however when displaying values to the users we will display them as decimals. This allows us to avoid floating point errors while keeping the values easy to work with from the users perspective.

When migrating current account balances over to the new system, we will multiple all coin balances by 100,000,000. We will initially be displaying up to 4 decimals in our apps however we would like to reserve the last 4 decimals if needed later on (when we scale).

  • the indivisible units are referred to as “bits”
  • the common/integer part are referred to as “coins”
  • 1 coins = 100,000,000 bits
# global constants
RESERVED_DECIMALS = 4
DENOMINATOR = 10 ** RESERVED_DECIMALS

# validate transaction amount
bit_amount = 20_000
is_valid = bit_amount % DENOMINATOR == 0

This ensures that the reserved decimals remain untouched.

bit_amount = 20_000  # is_valid would be True
bit_amount = 20_001  # is_valid would be False

Digits (1)

@buckyroberts buckyroberts assigned armansw and buckyroberts and unassigned armansw Feb 8, 2021
@buckyroberts
Copy link
Collaborator Author

Note to self - reserving decimals will lead to early inaccurate calculations, different results for the same calculations for earlier adopters and possibly migration/forking issues later. Instead of reserving decimals, we most likely want to just multiple all balances by 100,000,000 to convert values to bits and then just round on the UI (configurable, they can see full values if needed).

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

2 participants