title: MySQL Sorting when using FORMAT function
body: <p>I have a query that <strong>SUMS</strong> different values and then orders the results using <strong>ORDER BY</strong>.</p>
  
  <p>Whenever I format the result using <strong>FORMAT</strong> I get a different ordering than without format.</p>
  
  <p>For example:</p>
  
  <p>Ordering <strong>without</strong> format: 2827.0000, 1668.0000, 663.1000</p>
  
  <p>Ordering <strong>with</strong> format: 663.10, 2,827.00, 1,668.00</p>
  
  <p>What could be causing this behaviour?</p>
  
  <p>This is the full query:</p>
  
  <pre><code>SELECT
  FORMAT( ( (Sum(CASE WHEN YEAR(order_date) = 2015 THEN total END) / 100) - (SELECT COALESCE( ( SUM(total) / 100), 0) 
  FROM returns WHERE customer = orders.customer AND YEAR(return_dat) = 2015) ), 2) AS anual
  
  FROM orders
  
  WHERE 1 GROUP BY customer ORDER BY anual DESC
  </code></pre>