title: SQL money round to closest 0.05 cents
body: <p>I'm trying to round money in MySQL SELECT to the closest 0.05 cents.</p>
  
  <p>so numbers like: </p>
  
  <pre><code>140.70  should become 140.70
  140.71  should become 140.70
  140.72  should become 140.70
  140.73  should become 140.75
  140.74  should become 140.75
  140.75  should become 140.75
  140.76  should become 140.75
  140.77  should become 140.75
  140.78  should become 140.80
  140.79  should become 140.80
  </code></pre>
  
  <p>So more in detail</p>
  
  <pre><code>0.00 = 0.00
  0.01 = 0.00
  0.02 = 0.00
  0.022 = 0.00   // here the magic should happen 0.022 is closer to 0, so result is 0
  0.023 = 0.05   // but 0.023 should be rounded to 0.05! cause first round 0.023 to 0.025 which should then be rounded up to 0.05
  0.03 = 0.05
  </code></pre>
  
  <p>I've tried some different things with <a href="http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_ceil" rel="nofollow">MySQL CEIL()</a> and <a href="http://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_floor" rel="nofollow">MySQL FLOOR()</a> but couldn't get the right result.</p>
  
  <p>Created a <a href="http://sqlfiddle.com/#!9/c28a0f/1/0" rel="nofollow">SQL Fiddle here</a></p>
  
  <p>With a table which makes no sense, except we need one to SELECT from:</p>
  
  <pre><code>CREATE TABLE hello ( world varchar(255) );
  INSERT INTO hello (world) VALUES ('blubb');
  </code></pre>
  
  <p>This is the select Query:</p>
  
  <pre><code>SELECT 
  
   CEILING ( 0.05 / 0.05 ) * 0.05 AS CEIL_1,
   CEILING ( 0.06 / 0.05 ) * 0.05 AS CEIL_2,
   CEILING ( 0.07 / 0.05 ) * 0.05 AS CEIL_3,
   CEILING ( 0.08 / 0.05 ) * 0.05 AS CEIL_4,
   CEILING ( 0.09 / 0.05 ) * 0.05 AS CEIL_5
  
  FROM hello;
  </code></pre>
  
  <p>Anyone here telling me how to do it right?</p>