I need to print an array to an output file, the problem is that because of being numbers of different length and with decimal part is's impossible to align them with respect to the right margin. The only thing that was happened to me was a function using a block if elseif.. but I would like to know if there is some more efficient form

2.123 125.002 14.154
20.2569 12.123 17.158
-789.125 147.1 1.174

does anyone know how to align using the right margin?
thanks advanced