Want more information ?. Try the Web Home Page for this document.
All of the PSPDec, PSPDecAr and PSPNum classes support rounding of decimal numeric values.
For the PSPDec and PSPDecAr classes, you specify rounding on individual methods as in the following example:
// Construct PSPDec and PSPDecAr
PSPDec Dec1 = new PSPDec(11,2);
PSPDecAr DecAr1 = new PSPDecAr(11,2,5);
// Rounding occurs when value added to PSPDec
Dec1.addRound("123.456");
// Rounding does not occur when value added to PSPDecAr
DecAr1.add("123.456");
The Round property of the PSPNum controls how the PSPNum handles arithmetic rounding. You can set the Round property (a Java boolean) as in the following example:
// Construct PSPNum
PSPNum Num1 = new PSPNum(11,2);
// Then set rounding for subsequent operations
Num1.setRound(true);
// Rounding occurs when value added
Num1.add("78.976");
Rounding is only an issue when a new value assigned to a PSPDec/PSPDecAr/PSPNum has more digits after the decimal place than the PSP decimal object itself. If rounding is specified for the operation, the digit in the new value one place to the right of the DigitsAfterDP value is reviewed. If this is 0-4, no rounding occurs. If this is 5-9, rounding occurs. For example, if DigitsAfterDP has the value 2 and a new value assigned value is ".786", then the new value becomes ".79" if rounding is specified and ".78" if rounding is not specified.
Note that the sign of the value (positive or negative) is irrelevant for rounding. Also note that rounding only applies when a new value is assigned in program operations i.e. via direct assignment or arithmetic operations.
All rounding happens internally - you never get a final result for a PSPDec/PSPDecAr/PSPNum with more decimal places (DigitsAfterDP) than you specified for the PSP decimal object.
The rounding mechanism used by PSP decimal objects is equivalent to the
ROUND_HALF_DOWN rounding for the java.math.BigDecimal class. This rounding principle is also known
as 'half-adjust' in other computer languages. Other rounding principles are
possible, but the one we use is, in our opinion, the most consistent and easily
understood. It also avoids issues such as 'degrees of precision' and potential
pecuniary gain implicit in other rounding techniques.
For PSPNum objects, rounding does not apply to keystrokes. That is, if you key digits into the fractional portion of a PSPNum value, digits always scroll off to the right without any rounding.
The Round property defaults to true for a PSPNum when it is first
created. Round is one of the persistent PSPNum
properties. This means that any Round value you set can be saved for when an
application using the PSPNum restarts.