Zero-padding can be done for whole fields, so if you printed the result as two separate fields, you could do it. There is a method that is less than beautiful, but works. Say x is the value you want to print:
DOUBLE PRECISION x CHARACTER*6 y x = 123.4567 WRITE(y,'(F6.4)') x-int(x) WRITE(*,'(I3.3,A5)') int(x), y(2:5)
y declared as CHARACTER*6 because it needs to hold the fractional part of your number (4 decimal places), the leading zero and the decimal point. This can be easily changed if you want to show more decimal places, although it would be harder if you wanted to show a variable number of decimal places.
The field descriptor I3.3 means "print an integer with a maximum field width of 3 and leave zeros on the left so that there are always 3 digits." When printing values, we take y(2:5) to remove the top zero.
Happy coding!
c.anna
source share