Want more information ?. Try the Web Home Page for this document.

PSP Numeric Mask

Masking for PSP decimal numerics is provided by the PSPDecMask object which controls

Note that the size of the decimal number is never specified in the PSPDecMask. This is always controlled separately by the DigitsBeforeDP and DigitsAfterDP properties.

PSPDecMask objects are referenced by both PSPDec and PSPNum objects as follows:

PSPDecMask Reference By PSPDec objects By PSPNum Objects
PSPDecMask usage: Some PSPDec methods take PSPDecMask as parameter. PSPDecMask embedded within PSPNum.
PSPDecMask constructed: PSPDec and PSPDecMask constructed separately in your code. PSPNum constructor automatically constructs embedded PSPDecMask.
PSPDecMask mask set: By PSPDecMask.set(String) method. By PSPNum.setMask(String) method.
PSPDecMask mask retrieved: By PSPDecMask.get() and PSPDecMask.getUsed() methods. By PSPNum.getMask() and PSPNum.getMaskUsed() methods.

PSPDec Mask

For PSPDec objects, you construct the PSPDecMask separately and use it as follows:

// Create mask
PSPDecMask Mask1 = new PSPDecMask();
// Set/reset mask components
Mask1.set("[DP.][3S,][NB-][OBUS$ ]");
Mask1.set("[ZB*][3S,][PA+][NA-][NB]");
// Create separate PSPDec object
PSPDec Dec1 = new PSPDec(5,2,"12345.67");
// Derive formatted value of PSPDec
String Formatted = Dec1.toString(Mask1);
// Get used mask components
String Used = Mask1.getUsed();

PSPNum Mask

Because each PSPNum has an embedded PSPDecMask, you can set/get the mask values directly using the PSPNum:

// Create PSPNum with embedded mask
PSPNum Num1 = new PSPNum(5,2,"12345.67");
// Set/reset mask components
Num1.setMask("[DP.][3S,][NB-][OBUS$ ]");
Num1.setMask("[ZB*][3S,][PA+][NA-][NB]");
// Derive formatted value of PSPNum
String Formatted = Num1.getText();
// Get used mask components
String Used = Num1.getMaskUsed();

PSP Mask settings

It is generally a good idea to set critical mask values as early as possible for each PSPDec/PSPNum e.g. immediately after it is first created. Common mask settings are:

Negative number formatted Positive number formatted Mask
US$ -1,234.56 US$ 1,234.56 [OBUS$ ][NB-][3S,][DP.][DI.][DV.]
-1.234,56 1.234,56 [NB-][3S.][DP,][DI,][DV,]
1,234.56 CR 1,234.56 DR [NA CR][PA DR][3S,][DP.][DI.][DV.]

Mask Components

In the string value assigned to Mask, there must be one or more components delimited by [ ]. The first two characters following the opening '[' identify the mask component being set. Any characters after this and before the closing ']' are the new component value. For example, the mask component [DP.] means that the decimal place in an output formatted numeric value is being set to '.'. As another example, the mask component [DP and ] would set the same decimal place value to the phrase ' and '.

You may specify any number of components in each mask value. The values remain in effect until reset. So you can set/reset some components once, and reset other components repeatedly. All components are optional (do not have to be set in the Mask), with the exception of the DV component.

You can reset most components to NULL (nothing), by simply including no value. For example, the mask component [NB] sets the component identified by the letters 'NB' to NULL.

Most mask components control individual parts of the formatted value as follows:

ID Characters controlled in formatted value
OB Other (sundry) at very start of value. Example: ‘US$’ in ‘US$123.45’
NB -ve sign before digits. Example: ‘-’ in ‘-123.45’
PB +ve sign before digits. Example: ‘+’ in ‘+123.45’
ZB zero sign spacer before digits. Example: ‘(NOVALUE) ’ in ‘(NOVALUE) 0.00’
ZL Leading zero characters in integer digits. Example: ‘***’ in ‘***1.23’
3S Thousand-separator in integer digits. Example: ‘,’ in ‘12,345’
4S Ten-thousand-separator in integer digits. Example: ‘,’ in ‘123,4567’
DP Decimal place. Example: ‘ and ’ in ‘1 and 23’
NA -ve sign after digits. Example: ‘CR’ in ‘1.23CR’
PA +ve sign after digits. Example: ‘DR’ in ‘1.23DR’
ZA zero sign spacer after digits. Example: ‘ ZERO!’ in ‘0.00 ZERO!’
OA Other (sundry) at very end of value. Example: ‘ dollars’ in ‘1.23 dollars’

In addition, two mask components control how input decimal places as in the following table. Note that these apply only to PSPNum objects, not to PSPDec objects.

ID Input controlled
DI Input decimal place keyed in PSPNum edit box. For example, [DI.] identifies the full-stop character as the input decimal place. When you key a full-stop, PSPNum takes that keystroke position as being the new decimal place.
DV Input decimal place in numeric values assigned to the PSPNum via the Value property. For example, [DV.] specifies that in the parameter string to the PSPNum.setValue(String) method, the decimal place will be identified by the full-stop character. This is the only compulsory component. If you ever have a Mask value which does not include this component, PSPNum adds it automatically.

 

Rules and recommendations

The following rules apply to mask components:

In addition to the above rules, consider the following recommendations:

 

Mask Example

In the table below, the effect of new mask values are shown for a PSPNum/PSPDec with DigitsBeforeDP set to 6 and DigitsAfterDP set to 2. Note that mask revisions in the table are cumulative - that is, each row starts with settings from previous rows.

Mask set to -1234.56 formatted as: +1234.56 formatted as: Comment
[DP.][3S,][NB-] -1,234.56 1,234.56 Suitable for most countries - full-stop decimal place and comma for thousand-separator.
[3S.][DP,] -1.234,56 1.234,56 Swap output decimal place and thousand-separator (as in some European countries).
[DI,][DV,] -1.234,56 1.234,56 Also change input decimal place to comma.
[DI.][DV.][DP.][3S,][PB+] -1,234.56 +1,234.56 Leading plus sign for +ve values.
[NA-][NB] 1,234.56- +1,234.56 Move negative sign for-ve values to end.
[PA DR][PB] 1,234.56- 1,234.56 DR Show +ve values as debit.
[NA CR][NB] 1,234.56 CR 1,234.56 DR Show -ve values as credit.
[NB(][NA)] (1,234.56) 1,234.56 DR Show -ve values within brackets ().
[OBUS$ ] US$ (1,234.56) US$ 1,234.56 DR Use sundry initial characters for currency.
[NA CR][NB] US$ 1,234.56 CR US$ 1,234.56 DR Show -ve values as credit.
[OB][NA] 1,234.56 1,234.56 DR Drop currency and any indication for -ve value.
[ZL*] **1,234.56 **1,234.56 DR Introduce * for leading integer zeroes e.g. for cheque-print.
[ZL][DP $ and ][OA cents] 1,234 $ and 56 cents 1,234 $ and 56 DR cents Introduce text for parts of format.