×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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

(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

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

(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
        var(i)=adjustl(var(i))
        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.

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