I need to write data in scientific notation in a .dat file. For example Export["1.dat", {123.}]. I want to get 1.23e2 in 1.dat. But if I use ScientificForm I can only get ScientificForm[{123.}].

  • $\begingroup$ This can help you: mathematica.stackexchange.com/a/35375/280 $\endgroup$ – Alexey Popkov May 16 '18 at 2:00
  • $\begingroup$ Sorry But i don't think it works.Using his code my export is still 123 not 1.23e2, His method is mainly used to promote speed. $\endgroup$ – XinBae May 16 '18 at 3:10
  • $\begingroup$ You can replace FortranForm with ScientificForm or NumberForm (as in the answer by Carl Woll) in that solution in order to get the desired format. $\endgroup$ – Alexey Popkov May 16 '18 at 4:04

Maybe you can use NumberForm and OutputForm as follows:

    OutputForm @ NumberForm[
        N @ {Pi, E^3},
        NumberFormat -> (Row[{#1, "e", #3}]&),
        ExponentFunction -> Identity
Import["tst.dat", "String"]

"{3.14159e0, 2.00855e1}"

  • $\begingroup$ Thanks ! it is the format i want.But it caused another problem. How can i remove the` {}` in "tst.dat"? $\endgroup$ – XinBae May 16 '18 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.