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

Currency datatype / property #148

Open
joepio opened this issue Jan 30, 2023 · 0 comments
Open

Currency datatype / property #148

joepio opened this issue Jan 30, 2023 · 0 comments

Comments

@joepio
Copy link
Member

joepio commented Jan 30, 2023

Representing financial data has some interesting problems. In javascript, 0.3+0.6 = 0.899999999999. If you're building a webshop, and forget that this problem exists, you might make a painful mistake when rendering shopping cart totals. This problem is caused by how JS numbers are represented in memory (as floats).

Atomic Data distinguishes Integers from Floats. So you might say: let's store monetary data as integers! We could use the amoutn of cents, and that would work in most cases. However, what about very small prices that deal with fractions of a cent? Now we have no way of representing that.

We could also use a String datatype. That way, whatever the user inputs, is what is being stored. If they want a certain level of precision, they can just add characters. But know that the second we have to make calculations, we can still make these errors.

I'm not quite sure what is the best approach here. What should we recommend users do when they are modelling Classes with a currency-dependent property?

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