MD Code - Mask Decimal without Alignment

The MD code transforms numbers for display by scaling them and inserting symbols such as a decimal point, thousands separators, and a currency symbol. See the ML and MR codes for codes that are similar to the MD code but with more capability.

Input Conversion

Input conversion works with a number that has only thousands separators and a decimal point.

Syntax

MDprecision{scaling}{Z}{,}{$}{fieldWidth{fillerChar}}{creditChar}

Syntax Elements

precision A number (0-9) that specifies the number of digits to be output following the decimal point. Trailing zeros are inserted if necessary. If precision is omitted or 0 is specified, no decimal point is output.

scaling A number (0-9) representing the implied digits to the right of the decimal point as a scaling factor. That is, the stored value is descaled (divided) by that power of 10. For example, if scaling=2, the value is divided by 100; if scaling=3, the value is divided by 1000, etc.

If scaling is omitted, precision is used as the scaling factor.

If scaling is greater than precision, the stored value is rounded up or down to precision digits.

If the fieldWidth option is used and the Z, separator (,) and $ options are omitted, scaling is mandatory to avoid ambiguity with the fieldWidth element.

Note

The precision and scaling parameters can only be applied to numeric data; for details, refer to the ML and MR codes.

The definition of numeric data as it applies to the MD conversion code can be changed with the INT.MD.ONLY and MD.ICONV.ALWAYS environment options.

Z Suppress leading zeros. However, the output always includes a zero preceding the decimal point for fractional values (between 1 and -1) except that if the data is zero, there is no output.

, (comma) Specifies insertion of 1000th separators every three digits to the left of the decimal point.

The type of separator (comma or period) is specified with the SET-THOUS TCL command. The monetary unit separator is specified with the SET-DEC TCL command.

$ Appends an appropriate currency symbol to the number.

The currency symbol is specified with the SET-MONEY TCL command.

fieldWidth Aligns the currency symbol by creating a blank field containing fieldWidth columns. The value to be output overwrites the blanks.

fillerChar Optional. Specifies a filler character (see fieldWidth); can be any nonnumeric character including a blank.

If the creditChar option is used in addition to fieldWidth, fillerChar is mandatory.

creditChar Appends an appropriate credit character. The character can be specified as one of the following:

-Appends a minus sign to negative values. Positive or zero values are followed by a blank.

CAppends the characters CR  to negative values. Positive or zero values are followed by two blanks.

<Encloses negative values in angle brackets (<>).

Examples

In the following examples, assume that the output values are aligned through the R parameter in attribute 9 of the data definition item.

The following examples illustrate the alignment of the currency symbol and the insertion of a filler character:

MD Code

Stored Value

Output Value

MD2,$

1234567

$12,345.67

MD2,$12

1234567

$  12,345.67

MD2,$12*

12345

$*****123.45

MD2,$10 -

-12345

$  123.45-

In the final MD code listed above, there is a space immediately before the minus sign.

The following examples illustrate decimal precision of two positions and the insertion of a comma at each 1000th position:

MD Code

Stored Value

Output Value

MD2

1234567

12345.67

MD2,

1234567

12,345.67

MD0,

1234567

1,234,567

The following examples illustrate the use of the Z (zero suppress) option:

MD Code

Stored Value

Output Value

MD43Z

123

0.1230

MD43Z

0000123

0.1230

MD43Z

0012345

12.3450

The following illustrate the scaling factor, the Z (zero suppress), and c (credit) options:

MD Code

Stored Value

Output Value

MD64$12

00045678

$ 004.567800

MD46ZC

00045678

0.0457

MD46ZC

-0045678

0.0457CR

MD64Z<

-0045678

<4.567800>

MD64Z-

-0045678

4.567800-

MD64Z$12 <

-0045678

$< 4.567800>

Note

In the final MD code listed above, there is a space immediately before the less than sign.