Click on banner to return to main menu.

Money.h++ Code Example

Platforms: DOS, Windows, NT, OS/2, and UNIX workstations
Source and object code

Freedom from rounding errors

With Money.h++, the result balances

RWFixedDecimal52 debits="0";		The Rogue Wave RWDecimal types
RWFixedDecimal52 credits="0";		store fractions using base 10, so
debits+="1.00";				decimal fractions like 0.67 and 0.33
credits+="0.67";			are stored exactly, with no rounding
credits+="0.33";			error. Adding 67 cents and then adding
if(debits==credits);			33 cents is the same as adding a
cout<<"balances\n";			dollar! Because all of the arithmetic
else cout<<"doesn't balance\n";		is done exactly, the ledger balances.

With built-in C++ doubles, don't count on it

double debits = 0;			The built-in double types store 
double credits = 0;			fractions using base 2, so decimal
debits+=1.00;				fractions like 0.67 and 0.33 have 
credits+=0.67;				built-in rounding errors. Adding 67 
credits+=0.33;				cents and then adding 33 cents is not 
if(debits==credits);			the same as adding a dollar! Because 
cout<<"balances\n";			there is a built-in rounding error, 
else cout<<"doesn't balance\n";		the ledger doesn't balance.
Order now     Money.h++     Tools.h++

© Copyright 1995, Rogue Wave Software, Inc.