title: Formatting numbers when writing to files in Mathematica
body: <p>This is a continuation of <a href="https://stackoverflow.com/q/4943706/181759">this</a> question regarding number formatting, and related to my earlier <a href="https://stackoverflow.com/q/1687705/181759">question</a> about obtaining very specific Mathematica output to text files.</p>
  
  <p>I frequently have to use high precision in Mathematica for data generation but only need relatively low precision for visualization purposes. I also want to store the data for later use with all Symbol names and Array structures intact. For this I have been using <code>Save[]</code>, but there are two related problems.</p>
  
  <ol>
  <li><p>The high precision "pollutes" my results with superfluous digits which are very hard to get rid of:</p>
  
  <pre><code>In[1]  := b = SetPrecision[7, 50]; a = Pi/b
  Out[1] := 0.44879895051282760549466334046850041202816705705358654585356351318683091518373`50.
  In[2]  := InputForm @ N[a, 6]
  Out[2] := 0.44879895051282760549466334046850041203`6.
  </code></pre>
  
  <p>where I really only need 0.448799.</p></li>
  <li>Sometimes even the number indicating precision is corrupted and I get values like <code>4.72642364528438598726943'5.9999999999999999999999</code> where I don't generally need the precision and <code>4.72642</code> would suffice.</li>
  </ol>
  
  <p>Both of these introduce significant overhead to the file size, and while hard disk storage is cheap, file size makes a huge difference when later loading the files back into Mathematica.</p>
  
  <p>So, starting with, e.g., <code>aa</code> that contains 50 digit arbitrary precision numbers in an irregular array, is there a built in way for me to get a text file that would read something like this</p>
  
  <pre><code>aa = {{2.0437`4, 4.7276`4, ...}, ...}
  </code></pre>
  
  <p><strong>EDIT</strong>: To clarify, I am not having problems with the display of numbers or with tracking the precision of numbers or with changing the precision of numbers. What I am having trouble with is controlling how a number is written to a file.</p>
  
  <p>Using <code>N</code>, <code>NumberForm</code>, <code>OutputForm</code>, <code>InputForm</code>, <code>*Form</code>, etc, all do not work properly with <code>Save</code>. And <code>Save</code> is the only exporting option I can find that exports the symbol and array structure. <code>Export</code> and <code>Put*</code> can be used to control the formatting better but they don't include the symbol (and in the case of <code>Export</code> the array structure is lost as well).</p>