Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Writing number to string

Le_Callet__Morgan_M
405 Views

Dear all,

I am looking at the best way to write float and/or double value to a fixed filed format string (say 8 in length).

Over the year we have tried different format depending on the data range  but with the recent version of the compilers we have noticed some over flow or loss of accuracy.

Is there a generic way to ensure that we have the maximum accuracy when writing a number into a string considering the following special consideration:  70.6 can be written as -.0706+3.

Is there a guaranteed way to remove the leading 0 for value with a decimal point ?

Many thanks.

0 Kudos
3 Replies
DavidWhite
Valued Contributor II
405 Views

Gw.d[Ee] might do it, but I think there will still be at least one character lost for the E when needed.

If e is specified, the w should be greater than or equal to d + e + 5.

David

0 Kudos
andrew_4619
Honored Contributor III
405 Views

But double has about 17 significant figures so to not lose precision you need about 21 characters. If you use G0 the compiler selects the field width that is best for the size of the value.

0 Kudos
Steven_L_Intel1
Employee
405 Views

G0 won't give you an output value that will result in the same value read as input. Even 8 characters is not enough for a single precision if that's what you want.

0 Kudos
Reply