in reply to Strange int() result

You will need to check exactly how this database internally represents these quantities, and do precisely as the Romans do.   If it is known to be an integer number-of-cents, then I suggest that you take it as an integer ... bypassing any sort of input/output mask (which can introduce problems of its own).   Multiply the integer by one hundred, do the math, and then divide by 100 ... adding (subtracting) one if the (absolute value of the) remainder is 50 or more.   (This is the way that some, but not all, database systems handle the “currency” data type, and they normally use BigInts.)

It is extremely difficult to completely avoid “off by one cent” problems.   Usually the most important thing to make very-sure of is that all of the numbers that are printed on any customer’s statement do add up, because there will be some old cratchit out there who adds-up his phone bill “just to make sure,” and you don’t want him doing QA for you.

Replies are listed 'Best First'.
Re^2: Strange int() result
by Laurent_R (Canon) on Jun 18, 2014 at 22:45 UTC
    I agree, but, without bragging, I am most probably the best technical expert on this database and, more generally, the best technical expert on this application still working on it. Add to that that I am also certainly one of the top-five or at least top-ten functional experts on the application. And I make quite good money as an independent consultant on that expert knowledge (although, with such knowledge and knowhow, in the US, I would probably earn at least twice what I get here, but it's OK, I am not complaining). Well, I think I really know what I am talking about when I talk about this application.

      Excuse me, Laurent – I didn’t mean to insult you, and I publicly apologize to you now, if any offense was taken.   In part, my response was directed to “the peanut gallery” of others who might one day read this thread.   (Probably we have all experienced the “off by a penny” issue, and how can we explain to people that the computer’s total is actually more accurate?   I’ve long ago given-up on that ...)   By pointing out something that you already knew (of course), I did not mean in any way to suggest that you didn’t.   Again, I own my words, and I apologize sincerely.

        Don't worry, sundialsvc4, I certainly did not feel insulted or offended. The questions you asked are legitimate and you don't need to apologize. I only wanted to point out that if there is one technical subject that I really know well, inside out, it is this database and the application around it (including the different (at least 3, in some cases 4) levels of abstraction between the database level data types and the lowest, architecture dependent, level data types). So that I know that what I said about the data types used on this application is really accurate. But again, I certainly did not feel offended, no problem for me.