OConv Masked Decimal (MC, MD) function
Description
Converts an internal storage value to a decimal output format.
Syntax
output = OConv(string, "MDn | MDn [scale][,][Or m Or [mon]] [- Or < Or C Or D][P][Z][T][S][L][xc]")
Parameters
OConv (MC, MD) takes the following arguments for its parameters.
Parameters | Description |
---|---|
string | Must be either a number or a variable that contains a number. The value can be a decimal number. |
MD, MC | MD indicates a masked decimal conversion. MC (Masked Comma) uses a "." (period) to separate thousands and a "," (comma) to separate the fractional portion of a decimal number. |
N | Indicates the number of digits after the decimal point. Use the values A - F to specify 10 to 15 digits. The maximum value of n is F (15 digits). A 0 (zero) indicates no decimal point. You must specify a value for n. Use the scaling factor to adjust the results of multiplication or division on numbers that are already in internal format. For example, if you multiply 10.00 (internal format 1000) by 0.15 (internal format 15), the product should be 1.50. However, the internal format of the product is 15000. To assign the correct number of decimal places to the result, you must indicate a value for n of 2 (to display two decimal places). In addition, you must specify a scaling factor of 4 to cause the value in internal format to be divided by 10 to the 4th power. Remember that when you multiply two decimal numbers, the number of decimal places in the product is the sum of the number of decimal places in the two numbers. This number is the value of the scaling factor. For example, if you multiply 100.00 by 0.15, the result is 1.5000, a number with four decimal places. |
, (comma) | The "," (comma) option inserts commas to separate thousands. If you are using the MC option, substitute a "." (period) for the comma. |
$, m, or [mon] or [mox] | There are three ways to indicate monetary units: · Specify "$" (dollar sign) to prefix a "$" to the value. · Specify any other single, non-reserved character to prefix that character to the value. · Specify a series of characters, enclosed in square brackets, to prefix those characters to the value. To suffix the monetary unit instead of prefixing it, use the S option. MOX is used for international default conversions. Requires that a language is set in the environment, in field 15 (@environ.set<ENV_LND_DEFAULT$> ), eg LND_GERMAN_D, LND_FRENCH_F, etc., etc., etc. The language needs to be set within the SYSENV record prior to start. |
-, <, C, or D | There are four ways to indicate a negative value: · Specify a "-" (minus sign) to suffix a "-" to negative values. A positive value is suffixed with a single space. · Specify an "<" (angle bracket) to surround negative values with "< >". A positive value is suffixed with a single space. · Specify C to suffix negative values with one or more characters that indicate CREDIT. The characters actually displayed are identified in the active language set. A positive value is suffixed with as many spaces as the number of characters in the abbreviation for "credit" in the active language set, typically two ("CR"). · Specify D to suffix negative values with one or more characters that indicate DEBIT. The characters actually displayed are identified in the active language set. A positive value is suffixed with as many spaces as the number of characters in the abbreviation for "debit" in the active language set, typically two ("DB"). |
P | If you specify P and scale, and if string contains a decimal point, output is formatted to the number of decimal places indicated by n, but the location of the decimal place is retained. |
Z | The Z option outputs a value of 0 as null. |
T | The T option truncates data rather than rounding, when applying decimal (n) and scaling (scale) factors. |
S | The S option causes the monetary unit, if any, to be suffixed rather than prefixed to the value. |
L | If the absolute value of the number to be output is less than 1, the L option prefixes a 0 before the decimal point. If the number is 0, output is 0.0. The Z option overrides the L option. |
xc | Use the xc option to specify a fixed length for output and a fill character in case output is shorter than the fixed length. x is the length of the output and may be one or more digits. Use c to specify the character used to pad the output to the length specified by x. Note: If the length of the formatted output exceeds x, output is truncated. If you use the xc option, you must separate the values for n and x with at least one of the following: · a value for scale; or · any non-numeric option |
Example
The following table provides examples of the correct use of the OConv Masked Decimal function.
Example code | Output |
---|---|
OConv(1234, "MD0") | 1234 |
OConv(1234, "MD2") | 12.34 |
OConv(12, "MD2") | .12 |
OConv(150000, "MD24") | 15.00 |
OConv(12, "MD2L") | 0.12 |
OConv(1234, "MD2$") | $12.34 |
OConv(-1234, "MD2$") | $-12.34 |
OConv(-1234, "MD2$C") | $12.34CR |
OConv(-1234, "MD2$D") | $12.34DB |
OConv(-1234, "MD1-") | 123.4- |
OConv(1234, "MD2,10*") | *12.34 |
OConv(500, "MD0£") | £500 |
OConv(50, "MD0[DM]") | DM50 |
OConv(50, "MD0[DM ]") | DM 50 |
OConv(252525, "MC2.[<_>Bfr]S") | 2.525,25 Bfr |
OConv(-12345, "MC1.") | -1234,5 |
* When the language is set to LND_FRENCH_F, the following is observed * ee will contain 12345.67 preceded by the Euro Symbol ee = Oconv(1234567,'MOX')