4 ms·
I can’t count how many times I’ve individually solved this problem for various companies, and fixed broken ledger systems. I’m currently dealing with the terrib
by seancoleman 6y ago
I can’t count how many times I’ve individually solved this problem for various companies, and fixed broken ledger systems. I’m currently dealing with the terrible legacy decisions of single-precision float database columns leading to floating-point precision loss on a multi-million $$ eCommerce platform.
What a schlep.
I’m curious, do you store currency values as decimal dollars or integral cents?
- zomglings 6y agoThe code sample on the website indicates integral cents: // Transfer $10 from Alice to Bob decimals.transactions.create({ from_account: 'Alice', to_account: 'Bob', currency: 'usd', amount: 1000 })
- deleted 6y ago[deleted]
- andriosr 6y agoYep, as @zomglings and @vangale noted, always an integer. Thanks, guys. They can represent anything you want, cents, mils, and so on.
- pbreit 6y agoIronic that the app name is "Decimals". 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.
- WrtCdEvrydy 6y agoIt's an issue with floating point accuracy usually... 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.
- ajnin 6y agoHe's talking about fixed point, not floating point. The decimal type in SQL is an exact, fixed point numeric type. It can avoid loss of precision, like integer, but without the scale conversion step.
- mortin 6y agoThat's what we call "an abstraction" and that's what they were invented for. 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.