3 ms·
I thought finance worked using integers internally for this exact reason.
by lsaferite 11y ago
I thought finance worked using integers internally for this exact reason.
- roblabla 11y agoI figured they used Binary Coded Decimal [0] when they need to support decimals. [0] : https://en.wikipedia.org/wiki/Binary-coded_decimal https://en.wikipedia.org/wiki/Binary-coded_decimal
- lsaferite 11y agoWell, I know from doing payment gateway integration that many of them use integers for currency amounts. They are the smallest currency unit and for display you then convert based on the currency specific precision value.
- mannykannot 11y agoMaybe for accounts bookkeeping, but I doubt it is feasible, or even desirable, for financial statistical work.
- astine 11y agoAccounting systems I've worked with do most of their logic in a RDBM and store monetary types using a 'decimal' type.
- ars 11y agoThere are several ways to do it. One it so use fixed point decimal with a 1/100 scaling instead of floating point. So yes, integers and then you shift the decimal point when you output. But you have to watch out for interest calculations, you might earn a fraction of a penny on a daily basis but over a year it adds up and you can't throw away that accuracy. So you might do all math as floating point, but with pennies instead of dollars. Or you can do Binary Coded Decimal, which stores each group of decimal number after the decimal point exactly, in many ways it similar to fixed point decimal, since it is a fixed point.
- lsaferite 11y agoDo they do USD interest calculations in something smaller than 1/10000 (decimill I think)? The issue with BCD would be data store support and CPU support right? Do CPUs support doing math directly with BCD values and does your DB support doing math directly with BCD values? In any case, using floating point for any currency calculations is a huge no-no, even though a lot of things do it anyway. I work with Magento daily and all their currency math uses PHP floats and the rounding errors drive me bonkers.
- mehrdada 11y ago> Do CPUs support doing math directly with BCD values Perhaps surprisingly to some, x86 has instructions for BCD manipulation at the CPU level. Legacy.
- jerven 11y agoIn IBM POWER 6 this returned as an optimisation in hardware. https://books.google.ch/books?id=SPXHAgAAQBAJ&pg=PA44&lpg=PA44&dq=power7+binary+coded+decimal&source=bl&ots=6VseaHUdfE&sig=Dcs127eSide4fpqgIeX19U1UNOg&hl=en&sa=X&ved=0CB0Q6AEwAGoVChMIk7TYwOiQyQIVRfsOCh3AHwxw#v=onepage&q=power7%20binary%20coded%20decimal&f=false https://books.google.ch/books?id=SPXHAgAAQBAJ&pg=PA44&lpg=PA...
- dragonwriter 11y ago"Finance" uses lots of different things. Sometimes it uses symbolic math; sometimes it uses binary floating point, sometimes it uses decimal floating point, sometimes it uses arbitrary precision decimals or rationals, sometimes it uses integers in the smallest unit of concern for the application. Finance is a big domain.