title: How to store double values in a text file using minimum storage space?
body: <p>I am writing a simulation program that saves data to a .txt file. The data is read from the text file by another program that renders the data in the .txt file into .png images.</p>
  
  <p>The way that the program stores data is as follows:</p>
  
  <ul>
  <li>Each new line of the text file represents a new frame of simulation</li>
  <li>Each line consists of information about a particle</li>
  <li>The information that is saved for a particle is its X coordinate, Y coordinate, and mass, all three of which are doubles.</li>
  </ul>
  
  <p>Currently, the optimizations I've made are:</p>
  
  <ul>
  <li>Each double is truncated to the nearest thousandth in the file</li>
  <li>If a particle has collided and no longer exists, instead of writing <code>0.0 0.0 0.0</code> to the text file, <code>SKIP</code> is written.</li>
  </ul>
  
  <p>The output of ten frames of ten particles looks like this:</p>
  
  <pre><code>1.314 0.69 9.806 -0.108 -0.086 12.733 -0.83 0.44 10.161 1.302 0.671 9.662 1.526 0.0010 11.814 0.383 -0.612 10.432 -0.277 -0.754 10.871 1.582 -1.072 10.06 -0.554 -0.52 10.525 -0.516 -0.663 10.757 
  1.313 0.69 9.806 -0.108 -0.086 12.733 -0.83 0.439 10.161 1.303 0.67 9.662 1.526 0.0030 11.814 0.383 -0.612 10.432 -0.277 -0.754 10.871 1.581 -1.074 10.06 -0.554 -0.52 10.525 -0.515 -0.664 10.757 
  1.313 0.691 9.806 -0.108 -0.086 12.733 -0.831 0.438 10.161 1.303 0.669 9.662 1.526 0.0040 11.814 0.383 -0.612 10.432 -0.277 -0.754 10.871 1.58 -1.075 10.06 -0.555 -0.52 10.525 -0.515 -0.664 10.757 
  1.313 0.691 9.806 -0.108 -0.087 12.733 -0.831 0.437 10.161 1.304 0.668 9.662 1.526 0.0060 11.814 0.383 -0.612 10.432 -0.277 -0.754 10.871 1.579 -1.077 10.06 -0.555 -0.519 10.525 -0.514 -0.664 10.757 
  1.313 0.691 9.806 -0.108 -0.087 12.733 -0.832 0.436 10.161 1.304 0.667 9.662 1.526 0.0080 11.814 0.383 -0.612 10.432 -0.276 -0.755 10.871 1.578 -1.078 10.06 -0.555 -0.519 10.525 -0.514 -0.665 10.757 
  1.312 0.692 9.806 -0.108 -0.087 12.733 -0.832 0.435 10.161 1.305 0.666 9.662 1.526 0.0090 11.814 0.384 -0.612 10.432 -0.276 -0.755 10.871 1.577 -1.08 10.06 -0.556 -0.518 10.525 -0.514 -0.665 10.757 
  1.312 0.692 9.806 -0.108 -0.087 12.733 -0.833 0.434 10.161 1.305 0.665 9.662 1.526 0.011 11.814 0.384 -0.612 10.432 -0.276 -0.755 10.871 1.576 -1.081 10.06 -0.556 -0.518 10.525 -0.513 -0.665 10.757 
  1.312 0.692 9.806 -0.108 -0.087 12.733 -0.833 0.433 10.161 1.306 0.664 9.662 1.526 0.013 11.814 0.384 -0.612 10.432 -0.276 -0.755 10.871 1.575 -1.083 10.06 -0.556 -0.518 10.525 -0.513 -0.665 10.757 
  1.312 0.693 9.806 -0.108 -0.087 12.733 -0.834 0.432 10.161 1.307 0.663 9.662 1.526 0.014 11.814 0.384 -0.612 10.432 -0.276 -0.755 10.871 1.574 -1.084 10.06 -0.557 -0.517 10.525 -0.512 -0.666 10.757 
  1.311 0.693 9.806 -0.107 -0.087 12.733 -0.834 0.431 10.161 1.307 0.662 9.662 1.526 0.016 11.814 0.384 -0.612 10.432 -0.276 -0.755 10.871 1.572 -1.086 10.06 -0.557 -0.517 10.525 -0.512 -0.666 10.757 
  </code></pre>
  
  <p>Currently, a single frame of 100000 particles takes up 1.77 MB.</p>
  
  <p>Does anybody know how I should go about lowering that number?</p>