title: Sql function - disregarding the decimal place in returning value
body: <p>Why is it that sql query will disregard the decimal place when using SUM function?
  iv'e use CONVERT function but it doesn't return the right value. </p>
  
  <p>example:</p>
  
  <p>150.30 * 3 = 450.9</p>
  
  <p>but on the result of my function it return</p>
  
  <p>150.30 * 3 = 451 it round the decimal place.</p>
  
  <p>how can i get the exact result of calculation...?</p>
  
  <p>here's my sql function query</p>
  
  <pre><code>CREATE FUNCTION [dbo].[fnGetSubjectCost](@id INT)
  RETURNS DECIMAL 
  AS 
  -- Returns the stock level for the product.
  BEGIN
  DECLARE @ret DECIMAL;
  
  SELECT @ret = IIF([Name] = 'Tuition', CONVERT([DECIMAL](9,2),Cost) * CONVERT([DECIMAL](15,2),t1.SubjectUnit), CONVERT([DECIMAL](9,2),Cost))
      FROM [HCCDB].[dbo].[SubjectOfferedFee] AS t0
          INNER JOIN HCCDB.dbo.SubjectsOffered  AS t1
              ON t1.SubjectsOfferedID = t0.SubjectsOfferedID
              WHERE t0.SubjectOfferedFeeID = @id
  IF (@ret IS NULL) 
  SET @ret = 0;
  RETURN CONVERT(DECIMAL(15,2), @ret);
  END;
  </code></pre>
  
  <p>The query work but it did not return exact value. it disregard the decimal place.</p>
  
  <p>purpose of this function is the add on column formula.</p>
  
  <pre><code>ALTER TABLE HCCDB.dbo.SubjectOfferedFee
  ADD FinalCost AS CONVERT(DECIMAL(15,2), dbo.fnGetSubjectCost(CONVERT(INT, [SubjectOfferedFeeID])))
  </code></pre>