| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | C/Set++ |
DN>> You have just discovered why responsible programmers do not use
DN>> floating point arithmetic for financial applications. It is also one
DN>> reason why C has not replaced COBOL in the financial applications
DN>> area.
CM> Thanks for your response. I actually discovered this when I dug into
CM> those old, dusty programming texts, I've got on the shelf. I've
CM> worked arounf the problem for now by using doubles instead. This
CM> offers enough precision to carry through correctly for my
CM> application's needs.
It would be far better to use a structure for monetary amounts. (Or a money
class in C++)
typedef struct
{
ULONG dollars;
ULONG cents;
} MONEY;
typedef MONEY *pMONEY;
Then write you own math and display preperation functions such as:
AddMoney ( pMONEY, pMONEY, pMONEY);
SubtractMoney ( pMONEY, pMONEY, pMONEY);
MultiplyMoney ( pMONEY, pMONEY, pMONEY);
DivideMoney ( pMONEY, pMONEY, pMONEY);
FormatMoney ( char*, pMONEY);
It's not hard. Write it one time and use the code in every program you
write that deals with money. You'll never have to worry about floating
point errors creaping into your programs unnoticed. Use MONEY structures to
multiply and divide so you can hande fractions.
Carl
--- FleetStreet 0.90wb
* Origin: The Programmer's Assistant - Charlotte, NC - OS/2 - (1:379/4)SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413 SEEN-BY: 711/430 807 808 809 934 942 949 712/353 623 713/888 800/1 @PATH: 379/4 11 1 3615/50 229/2 12/2442 711/409 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.