Thank xwb and RenardPaul.
Since the length of the values can change, here is the code I tried. Little bit tedius but it seems to work.
__________________________________________
ws(1)=18.9
ws(2)=9999
ws(3)=1.3
n=3
do i=1,n
if (int(mod(ws(i),1.0)*10000).lt.0.0001) then
write (var(i), '(I8)') int(ws(i))
else
write (var(i), '(f8.2)') ws(i)
end if
end do
do i=1,n
var(i)=adjustl(var(i))
kk(i)=len_trim(var(i))
end do
write(*,'(<n>(A<kk(i)>,A1))') ((Var(i),','),i=1,n)
________________________________________