RWDecimal classes are primarily useful for their ability to represent and perform exact calculations with decimal numbers, including fractions. In this role they are distinct from the built-in floating point classes that silently and pervasively round numbers to approximations. For addition, subtraction, and multiplication, RWDecimal classes calculate the result exactly, and if the result cannot be represented within the limitations of the RWDecimal<T> an error handler is called.
Because division often results in a value that cannot be expressed exactly as a decimal fraction, division will frequently round results. For most purposes where performance is important, it is better to express division as multiplication (for example, a * 0.25 rather than a /4). If a program uses only the three exact arithmetic operators it will produce exact results for exact inputs.
©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.