ruby -e "puts sprintf('%.6e',1.123450e+2)" #=> 1.123450e+02
but I want '0.112345e+03', i.e., a leading zero placeholder.
Hmmm, now just need the '+0' part in the exponent and control
of the number of decimal places?
I am still not sure if you require sprintf.
I am not familiar with that but I will learn about it starting tomorrow. Thanks.
This code looks a bit strange to me and it is not very DRY.
Maybe someone will have a better solution soon. There must be a better way.
It may have some problems, so check it carefully. It is the best I can
offer you this late at night.
x = 1.12345e2
sig,y = 9, Math.log10(x).floor + 1
p (x*10**(y*-1)).to_s[0..sig+1].ljust(sig+2,"0") + "e+" +
y.to_s.rjust(2,"0") if y >= 0
p (x*10**(y*-1)).to_s[0..sig+1].ljust(sig+2,"0") + "e-" +
y.abs.to_s.rjust(2,"0") if y < 0
Harry