3
$\begingroup$

I am doing a calculation that I have set the precision to 20 i.e. N[expression,20] and the output on Mma is indeed 20 significant digits, but when I export this number to a txt file, I get more than that. Any idea how to remedy that, and my txt file to contain the same 20 digits that they are output to Mma?

$\endgroup$
4
$\begingroup$

You could try blocking $NumberMarks:

Block[{$NumberMarks=False},
    ExportString[N[{Pi, E, Pi^E}, 20], "Text"]
]
"3.14159265358979323846
2.71828182845904523536
22.4591577183610454734"

or:

Block[{$NumberMarks = False},
    Export["file.txt", N[{Pi, E, Pi^E}, 20], "Text"]
];
Import["file.txt", "String"]
"3.14159265358979323846
2.71828182845904523536
22.4591577183610454734"
$\endgroup$
  • 1
    $\begingroup$ Thank you. But would you have an explanation on why this happens? $\endgroup$ – hal May 13 at 18:11
  • $\begingroup$ Hi again. I tried what you proposed but it still doesn't work. The Mma GUI gives 20 digits significant precision, i.e. -6548.825915592645347 but the exported txt file gives -6548.82591559264534722455056080277298421799`19.81219934315515. $\endgroup$ – hal May 14 at 8:27
  • $\begingroup$ @hal What export format did you use, what was the exact Export call you used? And, what was the Mathematica version and OS? $\endgroup$ – Carl Woll May 14 at 13:41
  • $\begingroup$ Hi again, ok it worked. I didn't include the "Text" piece in the export. But any idea why without it, it fails to impose the $NumberMarks = False? $\endgroup$ – hal May 20 at 13:59

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.