title: adding numeric strings with commas
body: <p>I have a loop going which adds results from my database. The values are numeric strings in this format: $$$,$$$.$$ I am having trouble getting the results to add up and display in that same format:</p>
  
  <pre><code>function totals (){ 
      $result = mysql_query("SELECT meta_value FROM postmeta WHERE postmeta.meta_key = 'Value'");
      $value = 0;
      while( $row = mysql_fetch_array($result) ) {
          $value = $value + str_replace(',', '', $row['meta_value']);
      }
      echo "Worth $".$value."!";
  };
  </code></pre>
  
  <p>Using the above, I get something like Worth $653987.32!. Now I need to  reinsert the commas so I try this:</p>
  
  <pre><code>$value = number_format($value, 2, '.', ',');
  </code></pre>
  
  <p>But then I get Worth $10,000.00!</p>
  
  <p>Output as requested:</p>
  
  <pre><code>    original: 5,000.00   numeric: 5 
      original: 0.00   numeric: 0 
      original: 100.00   numeric: 100 
      original: 19.95   numeric: 20 
      original: 28.00   numeric: 28 
      original: 3,777.00   numeric: 3 
      original: 2,500.00   numeric: 2 
      original: 575.00   numeric: 575 
      original: 4,000.00   numeric: 4 
      original: 100.00   numeric: 100 
      original: 1,500.00   numeric: 1 
      original: 0.00   numeric: 0 
      original: 343.50   numeric: 344 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 1,070.00   numeric: 1 
      original: 305.00   numeric: 305 
      original: 1,000.00   numeric: 1 
      original: 0.00   numeric: 0 
      original: 50.00   numeric: 50 
      original: 1144.99   numeric: 1,145 
      original: 900.00   numeric: 900 
      original: 3,750.00   numeric: 3 
      original: 1,750   numeric: 1 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 200.00   numeric: 200 
      original: 619.00   numeric: 619 
      original: 200.00   numeric: 200 
      original: 50.00   numeric: 50 
      original: 0.00   numeric: 0 
      original: 2,699.00   numeric: 2 
      original: 0.00   numeric: 0 
      original: 10,000.00   numeric: 10 
      original: 500.00   numeric: 500 
      original: 186.00   numeric: 186 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 39,000.00   numeric: 39 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 8,330.00   numeric: 8 
      original: 0.00   numeric: 0 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 100.00   numeric: 100 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 4,875.00   numeric: 4 
      original: 1,000.00   numeric: 1 
      original: 3,135.00   numeric: 3 
      original: 15,000.00   numeric: 15 
      original: 400.00   numeric: 400 
      original: 75.00   numeric: 75 
      original: 100.00   numeric: 100 
      original: 6,893.00   numeric: 6 
      original: 330.00   numeric: 330 
      original: 484.96   numeric: 485 
      original: 8,600.00   numeric: 8 
      original: 2,500.00   numeric: 2 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 6,150.00   numeric: 6 
      original: 500.00   numeric: 500 
      original: 275.00   numeric: 275 
      original: 900.00   numeric: 900 
      original: 750.00   numeric: 750 
      original: 450.00   numeric: 450 
      original: 4,600.00   numeric: 4 
      original: 299.50   numeric: 300 
      original: 250.00   numeric: 250 
      original: 825.00   numeric: 825 
      original: 750.00   numeric: 750 
      original: 50.00   numeric: 50 
      original: 2,000.00   numeric: 2 
      original: 16,000   numeric: 16 
      original: 2,600.00   numeric: 2 
      original: 240.00   numeric: 240 
      original: 4,500.00   numeric: 4 
      original: 0.00   numeric: 0 
      original: 6,000.00   numeric: 6 
      original: 0.00   numeric: 0 
      original: 3,000.00   numeric: 3 
      original: 0.00   numeric: 0 
      original: 15,000.00   numeric: 15 
      original: 45,987.24   numeric: 45 
      original: 1,100.00   numeric: 1 
      original: 20,000.00   numeric: 20 
      original: 5,100.00   numeric: 5 
      original: 12,000.00   numeric: 12 
      original: 0.00   numeric: 0 
      original: 550.00   numeric: 550 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 150.00   numeric: 150 
      original: 4,500.00   numeric: 4 
      original: 1,500.00   numeric: 1 
      original: 0.00   numeric: 0 
      original: 1,758.00   numeric: 1 
      original: 450.00   numeric: 450 
      original: 400.00   numeric: 400 
      original: 28.00   numeric: 28 
      original: 20.00   numeric: 20 
      original: 50.00   numeric: 50 
      original: 20.00   numeric: 20 
      original: 22.00   numeric: 22 
      original: 99.00   numeric: 99 
      original: 500.00   numeric: 500 
      original: 500.00   numeric: 500 
      original: 33,080.00   numeric: 33 
      original: 3,000.00   numeric: 3 
      original: 5,000.00   numeric: 5 
      original: 25,000.00   numeric: 25 
      original: 25,750.00   numeric: 25 
      original: 5,000.00   numeric: 5 
      original: 1,800.00   numeric: 1 
      original: 419.75   numeric: 420 
      original: 600.00   numeric: 600 
      original: 130.00   numeric: 130 
      original: 1,000.00   numeric: 1 
      original: 650.00   numeric: 650 
      original: 650.00   numeric: 650 
      original: 285.00   numeric: 285 
      original: 949.00   numeric: 949 
      original: 500.00   numeric: 500 
      original: 798.80   numeric: 799 
      original: 279.50   numeric: 280 
      original: 369.90   numeric: 370 
      original: 0.00   numeric: 0 
      original: 5,000.00   numeric: 5 
      original: 1,995.00   numeric: 1 
      original: 1,800.00   numeric: 1 
      original: 0.00   numeric: 0 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 3,316.00   numeric: 3 
      original: 50.00   numeric: 50 
      original: 50.00   numeric: 50 
      original: 0.00   numeric: 0 
      original: 50.00   numeric: 50 
      original: 17,182.28   numeric: 17 
      original: 30,000.00   numeric: 30 
      original: 0.00   numeric: 0 
      original: 0.00   numeric: 0 
      original: 880.00   numeric: 880 
      original: 12.00   numeric: 12 
      original: 100.00   numeric: 100 
      original: 100.00   numeric: 100 
      original: 100.00   numeric: 100 
      original: 5,600.00   numeric: 5 
      original: 1,600.00   numeric: 1 
      original: 100.00   numeric: 100 
      original: 14.95   numeric: 15 
      original: 6,000.00   numeric: 6 
      original: 7,400.00   numeric: 7 
      original: 750.00   numeric: 750 
      original: 1,575.00   numeric: 1 
      original: 50.00   numeric: 50 
      original: 3,500.00   numeric: 3 
      original: 5,000.00   numeric: 5 
      original: 1,000.00   numeric: 1 
      original: 6,500.00   numeric: 6 
      original: 14,375.00   numeric: 14 
      original: 9,500.00   numeric: 9 
      original: 91,343.00   numeric: 91 
      original: 22,610.00   numeric: 22 
      original: 15,000.00   numeric: 15 
      original: 10,000.00   numeric: 10 
  </code></pre>
  
  <p>Clearly something isn't right. Can anyone help?</p>
  
  <pre><code>numeric total: 661,379 Original total: 661379.32
  </code></pre>