NumberToDisplayString function

Syntax

NumberToDisplayString(Format, Number [, Width] [, Precision])

Description

Use the NumberToDisplayString function to format Number according to the pattern specified in Format. The decimal and thousand's separator are formatted with what is with the current user's personalizations.

Specify the Width and Precision parameters when you want to dynamically specify the width or precision. Both width and precision can be set based on Format. For example, the following statically specifies the width to be 6, and the precision to be 2:

&MyValue = NumberToDisplayString("%6.2", &Num);

The following example show the width taken dynamically from the &Width variable:

&MyValue = NumberToDisplayString("%*.2", &Num, &Width);

The following example shows how both the width and the precision values are taken dynamically from the &Width and &Precision variables, respectively.

&MyValue = NumberToDisplayString("%*.*", &Num, &Width, &Precision);

Parameters

Parameter Description

Format

Specify the pattern for how Number is supposed to be formatted. See Using the Format parameter, below.

Number

Specify the number to be formatted.

Width

Specify the width of the string to be formatted.

Precision

Specify the precision of the string to be formatted.

Returns

A string value.

Example

In the following example, &Str1 would be "0001234,56".

&Num = 1234.56;
&Str1 = NumberToDisplayString("%#010.2t", &Num);

In the following example, &Str2 would be "$$$1234.56".

&Num = 1234.56;
&Str2 = NumberToDisplayString("%$10.2", &Num);

In the following example, &Str3 would be " 1,234.56".

&Num = 1234.56;
&Str3 = NumberToDisplayString("%10.2v", &Num);

In the following example, &Str4 would be "1.23456e+003".

&Num = 1234.56;
&Str4 = NumberToDisplayString("%w", &Num);

Using the Format Parameter

The Format parameter has the following format:

%[flags][width][.precision][R | T] [type]
  • Flags have the following format:

    Flag Description

    -

    Left align the number.

    $

    Fill out field on left hand side with international currency symbol.

    #

    Force the number to have a decimal point.

    blank

    Pad left hand side with blanks only indicating a negative number with a '-' sign.

    +

    Prefix output with plus sign.

    M

    Append " (cr)" on right for negative numbers and " (dr)" for positive numbers.

    m

    Opposite of M: " (dr)" for negative and " (cr)" for positive.

    A

    Bracket negative numbers with "[" and "]".

    a

    Bracket negative numbers with "(" and ")".

    q

    Display zeros as blanks.

    Q

    Display zeros as "None".

    0

    Pad left hand side with zeroes. This must be the last flag before any other pattern indicators.

  • Width must be specified as a non-negative integer. Specifying an asterisks ("*") allows for dynamic field width specification. The maximum width is 50.

  • Precision specifies how many digits follow the ".". It must be specified as a non-negative integer. Specifying an asterisks ("*") allows for a dynamic precision specification. The maximum precision is 50.

  • R specifies rounding in conversion from the internal PeopleCode representation, that is, specifying 12.345 with precision of 2 (%n.2Rt) prints 12.35. In the absence of the R control rounding is the default.

  • T specifies truncation in conversion from the internal PeopleCode representation, that is, specifying 2.345 with precision of 2 (%n.2Tt) prints 12.34.

  • Type has the following format:

    Type Description

    t

    Type has format like printf %f. For example, the form dddd.dddd. This is the default value.

    v

    1000ths separator delimited output. For example, if the separator is a comma, the format is 1,000,000.02.

    w

    Scientific format like printf %e. For example, the form d.ddddeddd where "e" indicates exponent. d specifies 1 decimal digit and dddd specifies an arbitrary number.

    W

    Scientific format (like above, for "w") except "e" is "E".

    z

    Scientific Engineering format like printf %e where the exponent is always a multiple of 3 and the mantissa is between 1 and a 1000.

    Z

    Scientific Engineering format (like above, for "z") except "e" is "E".

Related Topics