From: Glenn Jackman Date: 2009-09-29T00:30:05+09:00 Subject: Re: format problem At 2009-09-28 09:38AM, "Li Chen" wrote: > c=[ ['a','b','c'],['c1',2,1],['d1',3,4] ] > c.collect!{|row| row<<"\n"} > > File.open('test.txt','w') do |a_file| > c.each do |row| > row.each {|e| ("#{e}"=~/[a-zA-Z]|\n/) ? > (a_file.printf("%s\t",e)) : ( a_file.printf("%.2f\t",e)) } > end > end You might try checking if the element is a number, otherwise treat it as a string: c.each do |row| row.each do |elem| fmt = Numeric === elem ? "%.2f\t" : "%s\t" a_file.printf(fmt, elem) end a_file.puts end > ########output############# > > > a b c > c1 2.00 1.00 > d1 3.00 4.00 > > > ####expected as follow######## > a b c > c1 2.00 1.00 > d1 3.00 4.00 -- Glenn Jackman Write a wise saying and your name will live forever. -- Anonymous