Skip to content

Currency datatype / property #148

Open
@joepio

Description

@joepio

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions