F, D, E, and G Format Codes

Available Format Codes

The F, D, E, and G format codes are used to transfer floating-point values between memory and the specified file.

The syntax is:

[n]F[+][-][w][.d] 
[n]D[+][-][w][.d] 
[n]E[+][-][w][.d][Ee] 
[n]G[+][-][w][.d][Ee] 

where the parameters "n", "+", and "-" are as described in Syntax of Format Codes and the width specification is as follows:

w

is an optional width specification (0 ≤ ≤ 255). The variable w specifies the number of digits to be transferred. See Padding and Natural Width Formatting for additional details on the output width of a formatted value.

d

is an optional width specification (1 ≤ d < w). For the F, D, and E format codes, d specifies the number of positions after the decimal point. For the G format code, d specifies the number of significant digits displayed.

e

is an optional width (1 ≤ ≤ 255) specifying the width of exponent part of the field. IDL ignores this value—it is allowed for compatibility with FORTRAN.

On input, the F, D, E, and G format codes all transfer w characters from the external field and assign them as a real value to the corresponding input/output argument list datum.

The F and D format codes are used to output values using fixed-point notation. The value is rounded to d decimal positions and right-justified into an external field that is w characters wide. The value of w must be large enough to include a minus sign when necessary, at least one digit to the left of the decimal point, the decimal point, and d digits to the right of the decimal point. The code D is identical to F (except for its default values for w and d) and exists in IDL primarily for compatibility with FORTRAN.

The E format code is used for scientific (exponential) notation. The value is rounded to d decimal positions and right-justified into an external field that is w characters wide. The value of w must be large enough to include a minus sign when necessary, at least one digit to the left of the decimal point, the decimal point, d digits to the right of the decimal point, a plus or minus sign for the exponent, the character "e" or "E", and at least two characters for the exponent.

Note
IDL uses the standard C library function snprintf() to format numbers and their exponents. As a result, different platforms may print different numbers of exponent digits.

The G format code uses the F output style when reasonable and E for other values, but displays exactly d significant digits rather than d digits following the decimal point.

Overflow

On output, if the field provided is not wide enough, it is filled with asterisks (*) to indicate the overflow condition.

Default Values of the w, d, and e Parameters

If w, d, or e are omitted, the values specified in the following table are used.

Table 18-6: Floating Format Defaults

Data Type
w
d
e

Float, Complex

15

7

2 (3 for Windows)

Double

25

16

2 (3 for Windows)

All Other Types

25

16

2 (3 for Windows)

Format Code Examples

The following table shows the results of the application of various format codes to given data values. Note that normally, the case of the format code is ignored by IDL. However, the case of the E and G format codes determines the case used to output the exponent in scientific notation.

Table 18-7: Floating-Point Output Examples
("b" represents a blank space) 

Format
Internal Value
Formatted Output

F

100.0

bbbb100.0000000

F

100.0D

bbbbb100.0000000000000000

F10.0

100.0

bbbbbb100.

F10.1

100.0

bbbbb100.0

F10.4

100.0

bb100.0000

F2.1

100.0

**

e11.4

100.0

b1.0000e+02

1.0000e+002 (Windows)

Note that "e10.4" displays "**********" under Windows because the extra "0" added after the "e" makes the string longer than 10 characters.

E11.4

100.0

b1.0000E+02

1.0000E+002 (Windows)

g10.4

100.0

bbbbb100.0

g10.4

10000000.0

b1.000e+07

1.000e+007 (Windows)

G10.4

10000000.0

b1.000E+07

1.000E+007 (Windows)