4 ms·
Some languages have arbitrary precision types or use BCD. Next time you see someone using floating point types for money, please stop them. There's too many fin
by jrabone 14y ago
Some languages have arbitrary precision types or use BCD. Next time you see someone using floating point types for money, please stop them. There's too many financial libraries out there like OFX4J which get this wrong (or at least did the last time I looked).
- derleth 14y ago> Next time you see someone using floating point types for money ... apply that logic to their paycheck and let them deal with being underpaid by a bizarre amount because of rounding. Or apply it to their investment accounts so the errors accumulate for a few decades. Nothing like an object lesson to remedy bad behavior.
- icebraining 14y agoPython has Decimal for that. Unfortunately, the people who wrote the platform I use - which deals with money - decided they're "too slow".
- masklinn 14y ago> Unfortunately, the people who wrote the platform I use - which deals with money - decided they're "too slow". I've had the same problem (that platform wouldn't ha. It's… annoying (also bullshit: in the worst case — CPython <= 3.2 — basic arithmetic operations will take ~20µs on my machine aside from divisions which take a bit more and if that shows up in profiling use cdecimal, CPython 3.3 [integrated cdecimal] or pypy)
- ars 14y agoIf you don't have decimal types, then use fixed point. Or in simpler terms store cents (as integers) not dollars (as floats). Then add a decimal point when you display. If you are dealing with stocks or interest I suggest storing tenths, or hundreds of a cent to avoid rounding errors.