Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-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!
  • Students Click Here

*Eng-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

Fortran Format command

Fortran Format command

Fortran Format command


I am having difficulty using the FORMAT statement to output numbers to a specified number of decimal places.  The program is stated below and is a simple quadratic equation calculator.

If someone can help me it would be a great help.

Thanks in advance.




 REAL a, b, c, x1, x2

 WRITE (*,*) "Solving a Quadratic equation"
 WRITE (*,*) "Enter the three coefficients: "
 READ (*,100) a, b, c
100 FORMAT(3I1)

 CALL quad(a,b,c,case,x1,x2)
   CASE (1)
   WRITE (*,200) "The single root is:" ,x1
   CASE (2)
   WRITE (*,200) "The two real roots are " ,x1, " and " ,x2
   CASE (3)
   WRITE (*,200) "The real and imaginary parts are " ,x1, " and " ,x2
200 Format (F6.2)

 SUBROUTINE quad (a, b, c, case, x1, x2)
  REAL, INTENT(IN)::a,b,c
  REAL, INTENT(OUT)::x1,x2
  REAL d

  IF(a==0.0) THEN
  IF(d>=0.0) THEN

RE: Fortran Format command

delete statement 100 and read in a,b,c in free format with:-

 READ (*,*) a, b, c

as you appear to be reading them in as single integers.

To output the results with more decimal places just change statement 200 to say:-

 200 Format (F15.6)

or better still use the G format instead:-

 200 Format (G15.6)

and you will be able to output any value.


RE: Fortran Format command

It's been a long time, but ...

... I think you need to move your character strings from your WRITE statements to your FORMAT statement(s).

  200 FORMAT(" The single root is: ",F15.6)

Obviously you will then need more FORMAT statements.

RE: Fortran Format command

duh! Yes Denial, you're quite correct!

or perhaps change the format to:-

 200 Format (2(A,G15.6))


RE: Fortran Format command

Hi guys,

Thanks for your help.

I have tried both methods but with no success.  Basically I am getting a four decimal place output when I am trying to specify a 2 decimal place.

I have attached the two methods that were suggested.

As far as I can see that is the method to format an output?

Best Regards,

RE: Fortran Format command


If you want to force a 2 decimal place output then go back to the "F" format, but allow more space for larger numbers to be output, 6 characters as you had in F6.2 is seldom going to be enough.


   CASE (1)
   WRITE (*,200) "The single root is:", x1
   CASE (2)
   WRITE (*,200) "The two real roots are ", x1, " and ", x2
   CASE (3)
   WRITE (*,200) "The real and imaginary parts are ", x1, " and ", x2

200 Format (2(A,F15.2))


RE: Fortran Format command

Thank you Johnhors!

That is my problem solved.  Is the 2 in the statement

200 Format (2(A,F15.2))

because I have two variables, x1 and x2?

Thanks again

RE: Fortran Format command

Yes, and also because you have two characters strings (one with each real variable).

Be aware however that F15.2 limits the range of values that can be displayed (whereas G15.2 will change to exponential format to cover values outside the range of F15.2)


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 Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

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

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


White Paper - How ESI is Helping Move New Medical Device Product to Market Quicker & More Cost Effic
Early Supplier Involvement has long been a strategy employed by manufacturers to produce innovative products. Now, it almost seems like a necessity. Because decisions made in the design phase can positively affect product quality and costs, this can help add value to OEM bottom lines. This white paper will discuss many facets of ESI, including why it’s so valuable today, what challenges limit the benefits of ESI, how cost is impacted, and more. Download Now
White Paper - Moving to a Driverless Future
This white paper describes what we see as the best practices to support a sustainable engineering process for autonomous vehicle design. It exposes how to use simulation and testing in common frameworks to enable design exploration, verification and validation for the development of autonomous cars at a system, software and full-vehicle level to drive a mature product development process for automated driving. Download Now
Research Report - How Engineers are Using Remote Access
Remote access enables engineers to work from anywhere provided they have an internet connection. We surveyed our audience of engineers, designers and product managers to learn how they use remote access within their organizations. We wanted to know which industries have adopted remote access, which software they are using, and what features matter most. Download Now

Close Box

Join Eng-Tips® Today!

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

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close