1
$\begingroup$

My question is similar to this one, except the solution presented there does not work in my case since my table contains strings as well as numbers.

I would like to export data such as

data = List[List["A",3.0719`*^8],List["B",1.8483`*^8],List["C",6.93`*^6]];

to a file. Unfortunately, if I do

Export["data.csv",data];

the file contains the numbers in a shortened notation, such as 3.0719e8. I would like the file to save all digits without shortening anything, such that e.g. 3.0719e8 is saved as 307190000. How should I be doing that in Mathematica 11.3?

$\endgroup$
5
  • $\begingroup$ 3.0766e8 is saved as 307190000 does not look right. Are you saying that in your example 3.0719*^8 is saved as 3.0766e8? $\endgroup$ Oct 13, 2020 at 15:15
  • $\begingroup$ @RohitNamjoshi No, sorry, that was a typo, I've fixed it now. The digits stay the same of course, I'd just like to get rid of the e shorthand notation. $\endgroup$
    – Kagaratsch
    Oct 13, 2020 at 15:22
  • 1
    $\begingroup$ You could e.g. try: Export["filename, ToString@AccountingForm@data] $\endgroup$ Oct 13, 2020 at 15:28
  • $\begingroup$ @DanielHuber This seems to export a string of the mathematica list, not a csv table. $\endgroup$
    – Kagaratsch
    Oct 13, 2020 at 15:56
  • $\begingroup$ If you give your file another extension, e.g. ".dat", you will get: {{A, 307190000.}, {B, 184830000.}, {C, 6930000.}} and if you are not happy with the braces, you say: "Export["d:/tmp/test.dat", StringDelete[ToString@AccountingForm@data, "{" | "}"]] " . This will give you: A, 307190000., B, 184830000., C, 6930000. $\endgroup$ Oct 13, 2020 at 16:42

1 Answer 1

1
$\begingroup$

This combination works:

ExportString[
 MapAt[NumberForm@AccountingForm@# &, data, 
  Position[data, _Real]], "CSV"]

Output:

"A",307190000.
"B",184830000.
"C",6930000.

Tested on Mathematica 12.2.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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