Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss] Financial database / balance?



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.




BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org