in reply to How to calculate the sum of columns to be equal to 100?
In any programming language (much to the vexation of accountants ... who, I cordially submit, get whatever they deserve), dollars-and-cents when treated as floating-point numbers will not always add-up “to the penny.” In fact they can be off by several cents, depending on exactly how the information was processed.
One floating-point technique that is sometimes used is called banker’s rounding,” which rounds even-ending numbers one way, odd-ending numbers the other. (I don’t rightly recall if Perl implements it.) Another technique, used in (for instance) Microsoft Access for its CURRENCY data-type, is to use scaled integers. Internally, the number is multiplied by 10000 to give a fixed four digits of precision. But, even then, it might not add-up perfectly. It’s the math. Accountants, you see, inadvertantly “lose the money ahead of time” by rounding to (say) two decimal-places first. Their desk-calculators have a special mode to do that, which will produce different answers if instead set to ordinary floating-point mode. (Politically-connected accountants have a different mode yet, which allows the answer to be “anything you want!”) ;-)
Reproduce a similar issue in your accountant’s precious Microsoft Excel Spreadsheet, which you certainly can, and (s)he’ll be quiet(er).
ac - count - ant (n):
A person who will cheerfully spend a dollar looking for a penny, then bill you for it.au - dit -or (n):
A highly-paid professional who will certify that both answers are equally wrong.
Replies are listed 'Best First'. | |
---|---|
Re^2: How to calculate the sum of columns to be equal to 100?
by Laurent_R (Canon) on Aug 15, 2013 at 13:14 UTC | |
by Athanasius (Archbishop) on Aug 15, 2013 at 15:33 UTC | |
by Laurent_R (Canon) on Aug 15, 2013 at 18:53 UTC | |
by Laurent_R (Canon) on Aug 15, 2013 at 18:03 UTC | |
by Athanasius (Archbishop) on Aug 16, 2013 at 02:27 UTC |