Message Boards Message Boards

[✓] Change the format of exported float numbers?

GROUPS:

When i export numbers (from a list) to a .txt file that are smaller than $10^{-6}$ (or greater than $10^{6}$), Mathematica uses the Format with an asterisk and circumflex, e. g. exporting 0.000000456 yields 4.56*^-10 in the output file. What I want to have is the "e" format (e. g. 1.46e-7), because I'm reimporting the data to another Notebook and Mathematica gives me an error when I try to plot the data with the other format. I tried using FortranForm[] but the problem is, that the data is in a 2D array, that is Flattened for the export, like in this example:

test = {{1213214.124, 124124121.215, 1252154543.3}, {345, 765, 
    0.000000456}};
Export["data.txt", Flatten[test]];

which gives:

1.213214124*^6
1.24124121215*^8
1.2521545433*^9
345
765
4.56*^-7

what I want is:

1.213214124e6
1.24124121215e8
1.2521545433e9
345
765
4.56e-7

Also it would be important to keep the format of having one number in one line. Your help would be appreciated.

POSTED BY: Elias Fösleitner
Answer
2 months ago

Elias,

Use CSV format and it will work as you request:

Export["data.txt", Flatten[test], "csv"];

or

Export["data.csv", Flatten[test]];

Regards

Neil

POSTED BY: Neil Singer
Answer
2 months ago

Thank you very much for the quick answer :-)

POSTED BY: Elias Fösleitner
Answer
2 months ago

Group Abstract Group Abstract