What a schlep.
I’m curious, do you store currency values as decimal dollars or integral cents?
What a schlep.
I’m curious, do you store currency values as decimal dollars or integral cents?
// Transfer $10 from Alice to Bob
decimals.transactions.create({
from_account: 'Alice',
to_account: 'Bob',
currency: 'usd',
amount: 1000
})They can represent anything you want, cents, mils, and so on.
Personally, never liked the apps that used integers for what in the real/human world are decimals. I understand (sort of) why they are used from a tech perspective. But ultimately, tech is used by humans.
2 point decimals can usually be accurate but given enough operations, you can sometimes get a weird floating error and rounding / clamping is discouraged in banking.
At some point, in tech you are going to have to create an abstraction at some layer. The upper the layer, the more the abstraction should resemble what humans see as "normal".
Did you know all numbers are stored in "registries" in the computer memory. Is a registry a number? NO! It's just bits.
At what point can you actually treat a "variable" as an actual "decimal"?
How does a storage system actually save a decimal number? Not sure, and up to some point I don't care, as long as I know the accuracy and trade-offs I'm getting.
I guess my point is, using integers sets to represent a decimal number is okay if it is coping with the lower layers' limits. If a lower layer already provides a proper solution, then there is no need to provide the same.
But ultimately, abstractions are what matter and what has allowed us to progress. All you need to know about an abstraction is its limits and compromises.