Conversion from Built-In Floating Point

The Currency Module does not automatically provide conversion from a built-in floating point number to an RWDecimal<T> because such conversions often cause round-off errors. This situation occurs frequently with constants. For example, the following code

 

RWDecimal<RWMP2Int> x = 1.01;

will not produce an exact representation of 1.01, since the compiler interprets the constant as a floating point literal. To set x to an exact representation of 1.01, you can use a string or the form of the constructor that takes an integer and a number of decimal places. For example:

 

RWDecimal<RWMP2Int> x = "1.01"

or

 

RWDecimal<RWMP2Int> x(101,2);

If you do want to convert from a floating point number, use the global function.

 

RWDecimal<T> from(long double)

This will return a decimal object approximately equal to the parameter.