AX / D365FO – num2Str Function

Converts a real number to a string.

str num2Str(
    real number,
    int character,
    int decimals,
    int separator1,
    int separator2)

Parameters

ParameterDescription
numberThe real number to convert to a string.
characterThe minimum number of characters required in the text.
decimalsThe required number of decimal places.
separator1A DecimalSeparator enumeration value.
separator2A ThousandSeparator enumeration value.

Return Value

A string that represents the number.

Remarks

For the decimals parameter, the maximum value is 16. If a larger number is used, this method instead obtains a value for the decimals parameter from the local computer. In both cases rounding does occur.

Possible enumeration values for the separator1 parameter are:

  • 1 – point (.)
  • 2 – comma (,)

Possible values for the separator2 parameter are:

  • 0 – no thousands separator
  • 1 – point (.)
  • 2 – comma (,)
  • 3 – space ( )

Example

In the following code example, the first call to the num2str method provides 16 for the decimals parameter, and the second provides 17.

static void Job_Num2Str(Args _args)
    {
        real realNum = 0.1294567890123456777; // 19 decimals places.
        ;
        info(Num2Str(realNum,0,16,1,3)); // 16 decimal places
        info(Num2Str(realNum,0,17,1,3)); // 17 decimal places
    }

Output

The messages are in the following Infolog output. The first number in the display contains 16 decimal place digits, whereas the second contains only 2.

Message (10:18:12)

0.1294567890123457

0.13

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s