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
新分销商 I
2,719 次查看

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 项奖励
1 解答
nvaneck
新分销商 I
2,719 次查看
Or, Write (outputfile,'(I0,T10,I10) n1,n2

在原帖中查看解决方案

0 项奖励
5 回复数
Les_Neilson
重要分销商 II
2,719 次查看

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 项奖励
mohanmuthu
新分销商 I
2,719 次查看

Thank you Les!

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

0 项奖励
nvaneck
新分销商 I
2,720 次查看
Or, Write (outputfile,'(I0,T10,I10) n1,n2
0 项奖励
Les_Neilson
重要分销商 II
2,719 次查看

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 项奖励
mohanmuthu
新分销商 I
2,719 次查看

nvaneck wrote:

Or,

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

Most simplest form. Thank you!

0 项奖励
回复