title: How to display all stored decimals of float and real type?
body: <p>Recently I was doing a little experimenting around fixed precision and floating point types. What I found a bi of a nuisance is that I could not see all digits of float and real types. I tried casting to Decimal(30,20) but that gave me way to much decimals (precision) for decimals. My guess is that cast internally casts real to float(53) and then converts to Decimal(30,20). I ask myself how does this really work?</p>
  
  <p>Following <a href="http://sqlfiddle.com/#!3/9eecb7/4720" rel="nofollow">sql snippet (SqlFiddle)</a> illustrates the issue:</p>
  
  <pre><code>DECLARE @r real, @f float
  SET @r= 15.49
  SET  @f= 15.49
  SELECT 
      @r AS 'Real',
      CAST(@r as DECIMAL(30,20)) AS 'Real as Decimal',
      @f AS 'Float',
      CAST(@f as DECIMAL(30,20)) AS 'Float as Decimal';
  </code></pre>
  
  <p>This produces the following result:</p>
  
  <pre><code>Real      Real as Decimal        Float     Float as Decimal
  -----------------------------------------------------------
  15.49     15.489999771118164     15.49     15.49
  </code></pre>
  
  <p>The Real value @r is displayed as 15.49. I guess because it is rounded on 7th precision digit. Although it is not exact it is rounded to 15.49. The Decimal display puzzles me. Why so many decimals? What I wanted to achieve is get the all digits that are stored in real type.
  The float value is (I guess) precise enough so that value 15.49 can be stored exactly.
  So how to display all digits that are stored in real and float type correctly? Why does cast to Decimal not work as expected?</p>