Forum Moderators: coopster

Message Too Old, No Replies

Math advice, please

Why is the threshold .00001 for currency comparison?

         

albo

10:12 pm on May 2, 2005 (gmt 0)

10+ Year Member



I am learning PHP. I see in my training that "a good threshold for comparison of currency amounts is ".00001" (due to the way computers store numbers internally). I know of internal storage forms even from the old days when I programmed assembler on IBM 360/370. But I've also seen this threshold given for javascript etc. I have yet to understand why 5 digits are compared for eventual 2-digit rounding... Anyone with easily understood advice? (I don't need code, just reason)

ergophobe

4:53 pm on May 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I don't know, I'm just guessing.... I suppose that is a number where, if the error is random, you can be sure that it will be self-cancelling at a level where it won't result in a change in the actual rounded amount when you're done?

Or perhaps, allowing for relatively large sums, it allows precision within the range of a floating point number?

IEEE 64-bit format (8 8-bit bytes) allows for 14 digits, so

123,456,789.12345

so you can do currency amounts up to a billion dollars with that level of precision.

albo

7:49 pm on May 6, 2005 (gmt 0)

10+ Year Member



! I guess none of my clients will be involved with money in such large amounts.

My spouse showed me her real-estate calculator and indeed even it has four zeroes after the decimal point (allowing somewhat for even our small city's weird five-digit sales tax rate), but money around here, for sales, always gets rounded to cents. Mebbee except for weird sales tax I'll just stick with a three-digit threshold for now.

Thanks for your help!

ergophobe

8:33 pm on May 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ahh, there is that. Sales tax where I live is 8.25%, so totals are

x * 1.0825

In order to work with that number and save rounding until the end the four decimal places may avoid small errors.