MD

Formats numbers as monetary or numeric amounts, or converts formatted numbers to internal storage format. If the $, F, I, or Y options are included, the conversion is monetary.

If NLS is enabled and the conversion is monetary, the thousands separator and decimal separator are taken from the locale MONETARY convention. If the conversion is numeric, they are taken from the NUMERIC convention. The <, -, C, and D options define numbers intended for monetary use, and override settings in the MONETARY convention.

Syntax

MD n [ m ] [ options ]

n is a number, 0 through 9, that indicates the number of decimal places used in the output. If n is 0, the output contains no decimal point.

m specifies the scaling factor. On input, the decimal point is moved m places to the right before storing. On output, the decimal point is moved m places to the left. For example, if m is 2 in an input conversion and the input data is 123, it would be stored as 12300. If m is 2 in an output conversion and the stored data is 123, it would be output as 1.23. If m is not specified, it is assumed to be the same as n. Numbers are rounded or padded with zeros as required.

options are any of the following:

  • , specifies a comma as the thousands delimiter. To specify a different character as the thousands delimiter, use the convention expression.
  • $ prefixes a local currency sign to the number. If NLS is enabled, the sign is derived from the locale MONETARY convention.
  • F prefixes a franc sign to the number.
  • I is used with Oconv, specifies that the international monetary symbol for the locale is used. Used with Iconv, specifies that it is removed.
  • Y is used with Oconv. The yen/yuan character is used.
  • - specifies a minus sign as a suffix for negative amounts; positive amounts are suffixed with a blank space.
  • < specifies that negative amounts are enclosed in angle brackets for output; positive amounts are prefixed and suffixed with a blank space.
  • C adds the suffix CR to negative amounts; positive amounts are suffixed with two blank spaces.
  • D adds the suffix DB to negative amounts; positive amounts are suffixed with two blank spaces.
  • P specifies no scaling if input data already contains a decimal point.
  • Z outputs 0 as an empty string.
  • T truncates, rather than rounds, the data.
  • fx adds a format mask on output and removes it on input. f is a number, 1 through 99 indicating the maximum number of mask characters to remove or add. x is the character used as the format mask. If you do not use the fx option and the data contains a format mask, an empty string results. Format masks are described in Format Expression.
  • intl is an expression used to specify a convention for monetary or numeric formatting.
  • convention is an expression used to specify a convention for monetary or numeric formatting.

    The convention expression has the following syntax:

    [ prefix, thousands, decimal, suffix ]

    Note: Each element of the convention expression is optional, but you must specify the brackets and the commas in the right position. For example, to specify thousands only, enter [,thousands,, ].
    • prefix specifies a prefix for the number. If prefix contains spaces, commas, or right square brackets, enclose it in quotation marks.
    • thousands specifies the thousands delimiter.
    • decimal specifies the decimal delimiter.
    • suffix specifies a suffix for the number. If suffix contains spaces, commas, or right square brackets, enclose it in quotation marks.

Examples

The following examples show the effect of some MD (masked decimal) conversion codes with the Iconv function:

Conversion Expression
Internal Value
X = Iconv("9876.54", "MD2")
X = 987654
X = Iconv("987654", "MD0")
X = 987654
X = Iconv("$1,234,567.89", "MD2$,")
X = 123456789
X = Iconv("123456.789", "MD33")
X = 123456789
X = Iconv("12345678.9", "MD32")
X = 1234567890
X = Iconv("F1234567.89", "MD2F")
X = 123456789
X = Iconv("1234567.89cr", "MD2C")
X = -123456789
X = Iconv("1234567.89 ", "MD2D")
X = 123456789
X = Iconv("1,234,567.89 ", "MD2,D")
X = 123456789
X = Iconv("9876.54", "MD2-Z")
X = 987654
X = Iconv("$####1234.56", "MD2$12#")
X = 123456
X = Iconv("$987.654 ", "MD3,$CPZ")
X = 987654
X = Iconv("####9,876.54", "MD2,ZP12#")
X = 987654

The following examples show the effect of some MD (Masked Decimal) conversion codes with the Oconv function:

Conversion Expression
External Value
X = Oconv(987654, "MD2")
X = "9876.54"
X = Oconv(987654, "MD0")
X = "987654"
X = Oconv(123456789, "MD2$,")
X = "$1,234,567.89"
X = Oconv(987654, "MD24$")
X = "$98.77"
X = Oconv(123456789, "MD2['f','.',',']")
X = "f1.234.567,89"
X = Oconv(123456789, "MD2,['','','','SEK']"
X ="1,234,567.89SEK"
X = Oconv(-123456789, "MD2<['#','.',',']")
X = #<1.234.567,89>"
X = Oconv(123456789, "MD33")
X = "123456.789"
X = Oconv(1234567890, "MD32")
X = "12345678.9"
X = Oconv(123456789, "MD2F")
X = "F1234567.89"
X = Oconv(-123456789, "MD2C")
X = "1234567.89cr"
X = Oconv(123456789, "MD2D")
X = "1234567.89 "
X = Oconv(123456789, "MD2,D")
X = "1,234,567.89 "
X = Oconv(1234567.89, "MD2P")
X = "1234567.89"
X = Oconv(123, "MD3Z")
X = ".123"
X = Oconv(987654, "MD2-Z")
X = "9876.54"
X = Oconv(12345.678, "MD20T")
X = "12345.67"
X = Oconv(123456, "MD2$12#")
X = "$####1234.56"
X = Oconv(987654, "MD3,$CPZ")
X = "$987.654 "
X = Oconv(987654, "MD2,ZP12#")
X = "####9,876.54"