title: Obtaining decimal values in calculations in database
body: <p>Recently, I came across an anomaly that while dividing two integers, I am getting only the quotients and reminders are simply ignored.</p>
  
  <pre><code>SELECT 12/8,12%8 
  </code></pre>
  
  <p>The above query gives 1 and 4 respectively, which is similar to Java/C programming. Again applying Java/C programming methods used below calculations to obtain the expected value.</p>
  
  <pre><code>SELECT 12.0/8,12/8.0
  </code></pre>
  
  <p>The answer is 1.5000 and 1.5000 respectively.
  Working on my task I got a situation to obtain percentage value across two counted values (integers) and I stuck up with the results similar to the former query. Then I worked out through the same by multiplying one of the value with 1.0 . This solved my issue.</p>
  
  <p>But later on, going through few scripts, used in my project (developed long back), I noticed in certain cases the decimal values are returned from the query even though two counted values (whole numbers) are divided.</p>
  
  <p>I first noticed this in Netezza. But same holds true in SQL Server as well.</p>
  
  <p>Please advise on what basis the datatypes of returned values are decided.</p>