[Discuss] Financial database / balance?
Richard Pieri
richard.pieri at gmail.com
Sat Jan 14 21:04:41 EST 2012
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.
--Rich P.
More information about the Discuss
mailing list