in reply to Re: Strange int() result
in thread Strange int() result

My main client is a very large telecoms operator (35 million mobile phone customers, not counting those in the foreign and overseas subsidiaries) in Europe and I am working a lot on their mobile phone billing system. All the financial amounts are stored internally in the database as euro cents integers, with input and output masks providing for two decimal places.

Replies are listed 'Best First'.
Re^3: Strange int() result
by davido (Cardinal) on Jun 18, 2014 at 20:35 UTC

    Is euro-cents sufficient precision? In mjd's talk (and in his blog) he alludes to the fact that if you divide a term by a rate you'll end up with some rounding errors that are mitigated by millicents, and that in a larger scale might be best handled by microcents.


    Dave

      Well, using euro cent integer is sufficient precision for storing into the database amounts that will be simply added (or subtracted in the case of discounts) at the end of the billing period to produce the invoice.

      But when a calculation such as a multiplication or a division is involved, then, yes, some amounts (billing rates in the catalog, for example) are indeed stored in integer "millicents" (multiplied by 1E5) in order to get the right value in the end. I actually participated in 2009 to a project where we changed the catalog tariffs from 3 to 5 decimal point precision because it was the only way to get the right amount in the final invoice without any rounding error. Typically, if the marketing was selling a subscription for, say, EUR 19.90 (VAT inclusive) per month, it was impossible to find a before-tax rate to be stored in the catalog that would lead to exactly 19.90 after applying the tax rate (we would get, for example, either 19.91 or 19.89 after rounding). With a five decimal place catalog, any 2 decimal-place amount could be reached after applying the VAT rate. But this is really a rounding issue, not exactly the same thing as the floating point versus integer arithmetic problem (even though they are somewhat related).

      In my experience rounding issues and date management issues are some of the worst problems plaguing regularly information technology for business management. In the case of rounding issues, my client had to go through three large successive projects over a period of more than two years before getting rid completely of these rounding problems. The overall cost of these 3 projects is far in excess of one million euros, perhaps closer to or even above two million euros. I don't know exactly because I know (more or less accurately) only about the direct IT costs (studies, development and tests), but a lot of work from non IT persons (people from business departments, marketing, support, customer relationship, management, accounting, finance, tax, auditing, revenue assurance, SOX compliance, etc.) is also involved.