Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

Print out fomat for real number

Print out fomat for real number

Print out fomat for real number


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.


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

- if you want scientific format try
----> output  0.1230000E+02     9999
- or
----> output     12.3000002     9999

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

you could read the help of your compiler for more examples...
I recomand the scientific notation (not F4.1) for real numbers...your choice.

RE: Print out fomat for real number


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.

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

        do i=1,n
        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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close