# NumberForm with fixed width and exponent as "e+00" or "e-02"

I wish to export a matrix of real numbers out to a txt file in which the entries have the MatLab form:

7.568627450980391913e-01
1.000000000000000000e+00
3.176470588235293935e-01


Code Export["out.txt", ScientificForm[out,19,NumberFormat->(Row[{#1,"e",#3}]&)], "Table"]; doesn't do what I want. How can I remedy this?

## 1 Answer

Thanks to andre314 for providing the link and avni for the code in this post, the solution is:

Eform[x_?NumericQ,d_:18]:=Module[{m,e,mm,ee}, {m,e}=MantissaExponent[x+0.0];m=m*10;
If[m!=0,e=e-1,m=0.]; e=Clip[e,{-99,99}]; mm=ToString[PaddedForm[m,{d+1,d}]];
ee=If[-10<e<10,"0",""]<>ToString[Abs@e]; StringJoin[mm,If[e<0,"e-","e+"],ee]];

Export["out.txt",Map[Eform,out,{2}],"Table","FieldSeparators"->""];


(I thought there would be an easier, i.e. already built-in function for this, that's why I asked.)

• Carl Woll’s answer is much simpler and probably faster. I’d give that one a try too. Jun 11 '19 at 7:08