Scientific notation formatting

I have a value that I am displaying and it is appearing as 0.9944E+32

I have it set as

write(6, “(e13.4)”) corm

Where corm is holding a double precision value.

I’d like it to be displayed as:

9.9437E+32

However, increasing the 4 to 5 or the 13 does nothing.

Is this simple to do using just a standard format?

One thing you could do is to shift the decimal point by 1 digit (1p):

write(6, “(1pe13.4)”) corm

NOTE! non-trivially, the 1p addition will stick through the end of the format statement (i.e., if you have following numbers, it will also apply to them until you reset it say with 0p somewhere next). So, please handle with care…

That was the answer with f77. With modern fortran, a better approach would be to use an es13.4 or maybe an es0.4 format.

5 Likes

See - for example - https://www.intel.com/content/www/us/en/docs/fortran-compiler/developer-guide-reference/2023-2/es-editing.html

On output, the ES data edit descriptor transfers the real value of the corresponding I/O list item, right-justified and rounded to d decimal positions, to an external field that is w characters long if w is positive. The real value is output in scientific notation, where the absolute value of the significand is greater than or equal to 1 and less than 10 (unless the output value is zero).

Perfect; thank you!