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

Separating the sign from the value in IO format

DataScientist
Valued Contributor I
291 Views

This is more of a question about the Fortran standard:

Is there a way to separate the sign of a number from its value in the format of a write() statement?

For example,

```fortran

write(*,"(*(sp,' ',g0))") 1.23
end

```

yields,

```ascii

+1.2300000

```

while,

```ascii

+ 1.2300000

```

would be desired.

Thanks for any hints.

0 Kudos
1 Reply
jimdempseyatthecove
Honored Contributor III
273 Views
!  Console25.f90 
program Console25
    implicit none
    character(len=100) :: buffer
    write(buffer,"(*(sp,g0))") 1.23
    buffer = adjustl(buffer)
    buffer = buffer(1:1) // ' ' // buffer(2:)
    write(*,*) '|' // trim(buffer) // '|'
end program Console25
...
 |+ 1.230000|

Jim Dempsey

 

0 Kudos
Reply