Fixed and Floating Decimal Classes
For a floating decimal point class,RWDecimal<T>, the decimal point is changed as necessary when operations are performed. For a fixed decimal point class,RWFixedDecimal<T>, the number of digits after the decimal point is fixed. Fixed decimal classes are useful for representing, for example, bank account balances where there must always be exactly two decimal places. The following two code fragments illustrate the difference between floating and fixed classes:
 
RWDecimal<RWMP2Int> a = "12.34", b="0.123";
a += b; // a = 12.463
 
RWFixedDecimal<RWMP2Int> c = "12.34", d="0.123";
c += d; // c = 12.46
Once set, the number of decimal places for a fixed decimal point class remains constant. Any value later assigned to it will be rounded to that number of decimal places. An important exception to this rule occurs when an RWFixedDecimal<T> has the value null. When a fixed decimal class has a value of null, it will take on the number of decimal places of an assigned value. Since the default constructor produces a null value, this feature can be particularly useful. For example:
 
RWFixedDecimal<RWMP2Int> a("1.234");
RWFixedDecimal<RWMP2Int> b;
b = a;
is equivalent to
 
RWFixedDecimal<RWMP2Int> a("1.234");
RWFixedDecimal<RWMP2Int> b = a;
Elements of an array are initialized to a null value. This means that the number of decimal places for an element is not determined until a value is assigned to that element.