- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, I have a question about signes zero-values in a FORMAT-output.
The following code gives me as output -0.00.
[fortran]
program TestNegZero
implicit none
real*8 dTest
dTest=-0.001
write(*,'(f5.2)')dTest
end program TestNegZero
[/fortran]
In my old compiler (Compaq Visual Fortran), I got as output 0.00. I would like to achieve to get this output again, because I have a big program with calculation-outputs and there are now many cases with -0,00 as output.
Till now, I did not find a setting to manipulate the behaviour, is there a solution?
Thanks a lot for any advice and greetings from germany (therefore my english is not so perfect)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The CVF behavior was a bug. The standard requires that there be a sign when the original value is negative, even if it rounds to zero. There's no way to change this, sorry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, thanks for the info.
I just found out, that with the compiler-setting /vms (enable VMS Compatibility) the output is not signes anymore, but I think, this setting will for sure make me other problems.
So it seems, the onliest solution is to round myself every output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, /vms is doing something different here - it's establishing Fortran carriage control so that the sign is interpreted as carriage control. If you change the format to "1x,f5.2" you'll see the sign, even with /vms.
You could use an internal write and write to a string, and then if the string was equal to "-0.00" change it to " 0.00".

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page