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 | |
by locked_user sundialsvc4 (Abbot) on Jun 19, 2014 at 12:30 UTC | |
by Laurent_R (Canon) on Jun 19, 2014 at 18:48 UTC |