Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Left align numbers

mohanmuthu
New Contributor I
2,185 Views

Need to print two column of numbers (integers) with same width, with 1st column left aligned and 2nd column right aligned. Can someone help me?

0 Kudos
1 Solution
nvaneck
New Contributor I
2,185 Views
Or, Write (outputfile,'(I0,T10,I10) n1,n2

View solution in original post

0 Kudos
5 Replies
Les_Neilson
Valued Contributor II
2,185 Views

Something like :

character(widthRequired) leftString

integer firstNumber

integer secondNumber

write(leftString, *) firstNumber

leftString = adjustl(leftString)

write(outputfile,fmt) leftString, secondNumber

where fmt is say (A10, I10) and "10" is the widthRequired.

Hope this helps but you should look up ADJUSTL (and maybe ADJUSTR) in the help

Les

 

0 Kudos
mohanmuthu
New Contributor I
2,185 Views

Thank you Les!

I was trying out only with numbers and the string conversion worked for me.

0 Kudos
nvaneck
New Contributor I
2,186 Views
Or, Write (outputfile,'(I0,T10,I10) n1,n2
0 Kudos
Les_Neilson
Valued Contributor II
2,185 Views

nvaneck wrote:

Or,

Write (outputfile,'(I0,T10,I10) n1,n2

I had totally forgotten about format i0  I spend most of my life in C# now. Punishment but I don't know what I did wrong. :-)

0 Kudos
mohanmuthu
New Contributor I
2,185 Views

nvaneck wrote:

Or,

Write (outputfile,'(I0,T10,I10) n1,n2

Most simplest form. Thank you!

0 Kudos
Reply