# How to export InputForm of a number

I need to export full form of a number i.e. the actual form with which Mathematica works. For example, full form of a number is

num=1.169484510942700199072728900994741107537340948740235270571340.



Only way I found to export this is to write the following

InputForm[num];
ToString[%]
StringDrop[%, -4]
SetPrecision[%, StringLength[%]]


Now, the problem is that I want to export the whole table where each entry of the table has several inputs e.g.

tab={{1.19023593026210776265372476675229408385514142395807130236440., 1.170226157147376209932406660610133952695537443726790412412940.,
0.11026497024581008043204994118447096599401916146165634094839.473393763182095, 4.724132032335991327484178888773193162187546933175526780259440.,
46.079888548332736368645535224338518490359902367067149582286840., 26.251330709263137028588589289530799828946791223541518398700139.449222376362826,
8.630000986143715000557852704560834378284675129372460319982940., 0.328745277019366582130106825231842581575066762921615294272439.34155999202286, 0.240.},
{1.169484510942700199072728900994741107537340948740235270571340., 1.07361478438448377739837789510316819972541910244313875229440.,
0.108275466422480316552382423684565625515327717001199085538339.48226217386681, 4.588215884246550601787015633105337490650917534348183370612740.,
45.229591961771665401090652128264214624862373058971832773248440., 26.782035526859797926947060684146826649922681152123902784874839.444225614883074,
8.884044252135171969150613343727044521592762170105618520208140., 0.331716543472781695119713624272346401687192656529557613878839.33765542157627, 0.240.}}


and some of these entries are strings with variable lengths.

So, is there a way to circumvent this problem or a smarter way to extract full form of a number to a CSV table, that can later be imported in Mathematica and used?

• It does not make much sense to give more than 40 digits and then truncate it to Precision==40 (your backtick 40). If you export a number with Precision==40, 40 digits will be exported, what makes sense. Feb 11, 2021 at 17:19
• Am I understanding correctly that you are exporting from Mathematica to CSV and then re-import into Mathematica? If yes, then there are much simpler ways. Feb 11, 2021 at 17:32
• @Roman: yes, but I need to export full form of the number. I tried to export in the form e.g. num100=SetPrecision[num,100] but this doesn't work satisfactorily - when I use num100 as an input to the numerical code I don't get the same output as with num. Code is some stiff differential integrator so I need to keep track of a lot of digits Feb 11, 2021 at 17:56
• Some more questions: Are you aware that you can export binary representations (full forms) of everything? Why do you need to export anyway instead of just caching internally? The question looks very much like an XY problem. Feb 11, 2021 at 18:02
• It is irrelevant why I need to export the data. I need to store them for some reason. I think that question is formulated in a precise way - Is there a way to export full form of the number that can later be imported in that same form i.e. from 1.169484510942700199072728900994741107537340948740235270571340. I want 1.1694845109427001990727289009947411075373409487402352705713 and the method must work for other number that can have different precisions as indicated in the tab example. Feb 11, 2021 at 18:11

Export uses CForm under the hood for formatting of real numbers:

TracePrint[ExportString[.240, "CSV"], _ToString, TraceAction->Print@*FullForm]


HoldForm[ToString[CForm[0.240.],InputForm]]

"0.2"

So, one idea is to temporarily modify the CForm formatting of reals:

InternalInheritedBlock[{CForm},
Unprotect[CForm];
CForm /: ToString[CForm[r_Real], InputForm] := ToString[r, InputForm];
ExportString[tab, "CSV"]
]

(*
"1.19023593026210776265372476675229408385514142395807130236440.,1.\
170226157147376209932406660610133952695537443726790412412940.,0.\
11026497024581008043204994118447096599401916146165634094839.473393763182095,\
4.724132032335991327484178888773193162187546933175526780259440.,46.\
079888548332736368645535224338518490359902367067149582286840.,26.\
251330709263137028588589289530799828946791223541518398700139.449222376362826,\
8.630000986143715000557852704560834378284675129372460319982940.,0.\
328745277019366582130106825231842581575066762921615294272439.34155999202286,\
0.240.
1.169484510942700199072728900994741107537340948740235270571340.,1.\
07361478438448377739837789510316819972541910244313875229440.,0.\
108275466422480316552382423684565625515327717001199085538339.48226217386681,\
4.588215884246550601787015633105337490650917534348183370612740.,45.\
229591961771665401090652128264214624862373058971832773248440.,26.\
782035526859797926947060684146826649922681152123902784874839.444225614883074,\
8.884044252135171969150613343727044521592762170105618520208140.,0.\
331716543472781695119713624272346401687192656529557613878839.33765542157627,\
0.240."
*)

• this works, thanks! Feb 11, 2021 at 19:21

Why CSV? Why not mx?

Export["tab.mx", tab]
tabImport = Import["tab.mx"];

InputForm@tab == InputForm@tabImport
(* True *)
`