ML & MR

Justifies and formats monetary or numeric amounts. ML specifies left justification, MR specifies right justification. If the F or $ 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.

ML and MR

Syntax

ML | MR [ n [ m ] options [ ( fx ) ]

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.
  • 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.
  • Z outputs 0 as an empty string.
  • M specifies a minus sign as a suffix for negative amounts. Positive amounts are suffixed with a blank space.
  • E specifies that negative amounts are enclosed in angle brackets for output; positive amounts are prefixed and suffixed with a blank space.
  • N suppresses the minus sign on negative numbers.
  • $ prefixes a local currency sign to the number before justification. If NLS is enabled, the sign is derived from the locale MONETARY convention. To prefix a different monetary symbol, use the intl expression.
  • F prefixes a franc sign to the number.
  • ( fx ) adds a format mask on output and removes it on input. x is a number, 1 through 99 indicating the maximum number of mask characters to remove or add. f is a code specifying the character used as the format mask, and is one of the following:
    • # specifies a mask of blanks.
    • * specifies a mask of asterisks.
    • % specifies a mask of zeros.
  • intl is an expression used to customize output according to different international conventions, allowing multibyte characters.

    The intl 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. If thousands contains spaces, commas, or right square brackets, enclose it in quotation marks.
    • decimal specifies the decimal delimiter. If decimal contains spaces, commas, or right square brackets, enclose it in quotation marks.
    • suffix specifies a suffix for the number. If suffix contains spaces, commas, or right square brackets, enclose it in quotation marks.

Literal strings can also be enclosed in parenthesis. Format masks are described in Format Expression.

Examples

The following examples show the effect of some ML and MR conversion codes with the Iconv convention:

Conversion Expression
Internal Value
X = Iconv("$1,234,567.89", "ML2$,")
X = 123456789
X = Iconv(".123", "ML3Z")
X = 123
X = Iconv("123456.789", "ML33")
X = 123456789
X = Iconv("12345678.9", "ML32")
X = 1234567890
X = Iconv("1234567.89cr", "ML2C")
X = -123456789
X = Iconv("1234567.89db", "ML2D")
X = 123456789
X = Iconv("1234567.89-", "ML2M")
X = -123456789
X = Iconv("<1234567.89>", "ML2E")
X = -123456789
X = Iconv("1234567.89**", "ML2(*12)")
X = 123456789
X = Iconv("**1234567.89", "MR2(*12)")
X = 123456789

The following examples show the effect of some ML and MR conversion codes with the Oconv function:

Conversion Expression
External Value
X = Oconv(123456789, "ML2$,")
X = "$1,234,567.89"
X = Oconv(123, "ML3Z")
X = ".123"
X = Oconv(123456789, "ML33")
X = "123456.789"
X = Oconv(1234567890, "ML32")
X = "12345678.9"
X = Oconv(-123456789, "ML2C")
X = 1234567.89cr"
X = Oconv(123456789, "ML2D")
X = " "1234567.89db"
X = Oconv(-123456789, "ML2M")
X = "1234567.89-"
X = Oconv(-123456789, "ML2E")
X = "<1234567.89>"
X = Oconv(123456789, "ML2(*12)")
X = "1234567.89**"
X = Oconv(123456789, "MR2(*12)")
X = "**1234567.89"