×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Print out fomat for real number

## Print out fomat for real number

(OP)

Hi, how should I output real varibles Var/12.3,9999/ as 12.3 9999 by using F4.1 rather than 12.3 9999.9 by using F6.1. I am using Microsoft Visual Fortran.

Thanks

### RE: Print out fomat for real number

Try G12.4.  It will give 12.30 and 9999. with 4 leading and 4 trailing spaces.  Maybe your implementation of G is different from GNUs and will give you what you want.  Also check if it has B and Z descriptors.  They do some extras on some implementations.

### RE: Print out fomat for real number

you have a real number and a integer number, so you have to use diferent FORMAT for them
example_1

- if you want scientific format try
E15.7,1x,I8
----> output  0.1230000E+02     9999
- or
F15.7,1x,I8
----> output     12.3000002     9999

example_2
x=12.3 ; n=9999
write(*,100)x,n
100 format(E15.7,1x,I8)
end

I recomand the scientific notation (not F4.1) for real numbers...your choice.

### RE: Print out fomat for real number

(OP)

Thank xwb and RenardPaul.

Since the length of the values can change, here is the code I tried. Little bit tedius but it seems to work.

__________________________________________
ws(1)=18.9
ws(2)=9999
ws(3)=1.3
n=3

do i=1,n
if (int(mod(ws(i),1.0)*10000).lt.0.0001) then
write (var(i), '(I8)') int(ws(i))
else
write (var(i), '(f8.2)') ws(i)
end if
end do

do i=1,n
kk(i)=len_trim(var(i))
end do

write(*,'(<n>(A<kk(i)>,A1))') ((Var(i),','),i=1,n)
________________________________________

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!