5 ms·
I’ve not done any real finance programming, so is this a reasonable explanation? Currency is stored as a count of cents (millicents if being fancy). Therefore
by DougBTX 8y ago
I’ve not done any real finance programming, so is this a reasonable explanation?
Currency is stored as a count of cents (millicents if being fancy). Therefore the two main features of floats are not useful:
- Support for very small numbers is not needed. Floats dedicate approx half their range to numbers between -1 and +1, this is wasted when counting whole cents.
- Support for very large numbers at the expense of precision is actively bad, as the precision must always be down to individual cents.
So the useful range of floats is much reduced when using floats for counting, approx 54 bits out of a 64 bit float are used. Instead ints (“counting numbers”) are much better for counting cents than floats (which approximate the continuous real numbers in a finite number of bits).