Formatting Variables for Output

Variables of the CHARACTER format (string variables) are printed "as is", with no special formatting. All characters stored in the variable (including spaces) are printed. Some DEF parameters also control the output format. For instance, there is a parameter to force all output to be upper-case.

Variables of all other formats (numeric variables) are formatted for output according to the following options:

Format Option

Comment

Max. digits for integer part

Up to 9 digits. Values that cannot fit within that number of digits generate a runtime error.

Max. digits for fractional part

Up to 9 digits. The number is rounded to that number of fractional digits.

Note: Setting to zero will result in integer-only output.

Min. digits for integer part

If the integer part does not need that number of digits, leading zeros or spaces will be used. Must be less than or equal to the maximum digits.

Min. digits for fractional part

If the fractional part does not need that number of digits, trailing zeros or spaces will be used. Must be less than or equal to the maximum digits.

Leading zeros (Yes / No)

Choose between zeros (if Yes) and spaces (if No), if the minimum number of integer digits is not met.

Trailing zeros (Yes / No)

Choose between zeros (if Yes) and spaces (if No), if the minimum number of fractional digits is not met.

Character for the plus (+) sign

If left blank or set to ~, no sign character will be printed for positive numbers. Otherwise, a sign character will be used (For example, +3.2).

Character for the minus (-) sign

If left blank or set to ~, no sign character will be printed for negative numbers. Otherwise, a sign character will be used (For example, -3.2).

Character for the decimal point

Any character except space (usually a dot)

Use decimal point for integer numbers (Yes / No)

If set to Yes, a decimal point will be printed even for integer values (For example, 2. instead of 2)

Representation of the value 0

Exact string to be used (For example, 0.0) when value is 0 (all other formatting options are ignored).

The following examples assume the following:

  • The standard characters are used for the decimal point (.) and the minus sign (-).

  • No character is used for the plus sign (so positive numbers are printed without a preceding + sign).

  • Decimal point is not used for integer values.

  • In the examples, trailing spaces are shown as underscores (_) for clarity, they are actually spaces.

Variable Value

Max. int. digits

Max frac. digits

Min. int. digits

Min frac. Digits

Leading zeros

Trailing zeros

Output

6.6666…

4

3

0

0

No

No

6.667

6.6666…

4

1

0

0

No

No

6.7

6.6666…

4

3

2

0

No

No

 6.667

6.6666…

4

3

2

0

Yes

No

06.667

25.0

5

0

1

0

Yes

Yes

25

24.9

5

0

1

0

Yes

Yes

25

25.1

5

4

3

2

Yes

Yes

025.10

25.1

5

4

3

2

No

No

 25.1_

2000.0

3

2

1

0

No

No

Error!

-0.333...

4

3

0

0

No

No

-0.333

Notes:

  • A runtime error occurs when the number to be formatted exceeds the maximum number of digits allowed for the integer part.

  • In an integer-only format (when the maximum number of fractional digits is zero), non-integer numbers are rounded. It does not affect their internal value, only the formatted output string.

  • Although it is theoretically possible to define an 18 digit number (setting both maximum digits to 9), this is beyond the actual accuracy of double precision numbers. Practically, no more than 14 significant digits can be formatted.

  • The REAL format is internally defined with 14 maximum digits for the integer part and 14 maximum digits for the fractional part. The minimum number of digits for the integer and fraction parts is set to 1. The numbers set in the DF2 file for these options have no effect on the REAL format. Other options (like leading or trailing spaces) do affect the REAL format. However, it is advised to leave the REAL default definition as is.

  • A comma (,) can be used for the decimal point character, instead of the standard dot (.). This is common in Germany (for example, 0,5 means 1/2).

  • If the decimal point character is omitted, the output may be erroneous. For instance, if max fraction digits is 1, then 6.6666… will be formatted as 67 instead of 6.7 - as if multiplied by 10!

GPP Compatibility Notes:

In the old GPP, the formats also defined the default modality for variables of this format. In GPP2, formats do not define modality at all (this parameter was removed from the format) and all variables are non-modal by default.

Some functionality may be dependent on the product package. Contact your Reseller if you require a license.