Exporting numbers to a file like printf
- To: mathgroup at smc.vnet.net
- Subject: [mg41066] Exporting numbers to a file like printf
- From: "Lawrence A. Walker Jr." <lwalker701 at earthlink.net>
- Date: Wed, 30 Apr 2003 04:25:58 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Is it me or is exporting numbers to a file using Mathematica really tough?
Most of the time I need fine control over how Mathematica output data to
a text file -- sort of like the printf in C.
If I am not careful Mathematica will print out numbers in 2D scientific
notations. This messes everything up because the data takes up two lines!
After much experimentation I came across two constructs:
(1) ToString[PaddedForm[FortranForm[SetPrecision[num,15]],{6,5},
NumberSigns->{"",""}]]
(2) ToString[PaddedForm[num, {17, 10}, ExponentFunction -> (Null &)]]
In the (1) I used SetPrecision[ ,15] because without it Mathematica kept
formatting certain numbers to machine precision instead of the precision
I specified.
In (2), the ExponentFunction option was necessary to suppress the 2D
scientific notation formatting.
Does anyone know a better way for mimicking the printf function?
And of course, the WriteString function can be used to export the
'numbers' to a file.
Thanks,
Lawrence
--
Lawrence A. Walker Jr.
http://www.kingshonor.com