You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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?
The text was updated successfully, but these errors were encountered: