[Discuss] Financial database / balance?

Jerry Feldman gaf at blu.org
Sun Jan 15 08:07:19 EST 2012


On 01/14/2012 09:04 PM, Richard Pieri wrote:
> On Jan 14, 2012, at 1:23 PM, markw at mohawksoft.com wrote:
>> That's a HORRIBLE idea! 3 decimal places are worse that IEEE. If it just a
>> home accounting package, use doubles. If it is for the banking industry
>> use a financial math library.
> IEEE-754 is exactly what you don't want to use.  Rounding errors in floats and doubles will introduce errors into your calculations.  Here's an example:
>
> // some code to print a floating point number to a lot of decimal places
> int main()
> {
>     double f = .37;
>     printf("%.20f\n", f);
> }
> $ gcc -O -o foo foo.c
> $ ./foo
> 0.36999999999999999556
>
> Code snippet modified from:
> http://www.theregister.co.uk/2006/08/12/floating_point_approximation/
>
> As you can see, the internal representation of the number is not the number.  It's close, so very close, but "close" is the same as "wrong" in accounting.
>
Actually, most spreadsheets use doubles. Back when I was at Cadmus in
the early 1980s there was one of our third party spreadsheet vendors who
used floats, and we strongly advised against it. But, as you point out
above and I pointed out in parallel floats are approximations, but they
are used in some financial calculations. Note that the maximum precision
of a double is 15 decimal places so the 556 is simply garbage. Also,
nearly all microprocessor chips implement IEEE (format in my previous
email). Some vendors (like Digital VAX) had different formats. But all
floating point numbers are stored in binary with an exponent and mantissa.

-- 
Jerry Feldman <gaf at blu.org>
Boston Linux and Unix
PGP key id:3BC1EB90 
PGP Key fingerprint: 49E2 C52A FC5A A31F 8D66  C0AF 7CEA 30FC 3BC1 EB90




More information about the Discuss mailing list