Rounding problem with my result I have a rounding problem with the result of a query as shown below, where it feels that somewhere along the calculation the result was truncated. The result is 

 

The SQL query is:

SELECT      
    "wos"."ISOVERDUE" AS "Broken SLA",
    (COUNT("wo"."WORKORDERID")) * 100 /(
       SELECT COUNT(*)
       FROM   "WorkOrder" "wo"
       WHERE  wo.ISPARENT = '1'
              AND wo.CREATEDTIME &gt;= &lt; from_thismonth &gt; 
              AND wo.CREATEDTIME &lt;= &lt; to_thismonth &gt;
     ) AS "%"

FROM "WorkOrder" "wo"       
LEFT JOIN "ModeDefinition" "mdd" ON "wo"."MODEID"="mdd"."MODEID" 
LEFT JOIN "SDUser" "sdu" ON "wo"."REQUESTERID"="sdu"."USERID" 
LEFT JOIN "AaaUser" "aau" ON "sdu"."USERID"="aau"."USER_ID" 
LEFT JOIN "DepartmentDefinition" "dpt" ON "wo"."DEPTID"="dpt"."DEPTID" 
LEFT JOIN "WorkOrderStates" "wos" ON "wo"."WORKORDERID"="wos"."WORKORDERID" 
LEFT JOIN "CategoryDefinition" "cd" ON "wos"."CATEGORYID"="cd"."CATEGORYID" 
LEFT JOIN "WorkOrder_Queue" "woq" ON "wo"."WORKORDERID"="woq"."WORKORDERID" 
LEFT JOIN "QueueDefinition" "qd" ON "woq"."QUEUEID"="qd"."QUEUEID" 

WHERE   wo.ISPARENT='1' AND wo.CREATEDTIME &gt;= &lt;from_thismonth&gt; AND wo.CREATEDTIME &lt;= &lt;to_thismonth&gt;

GROUP BY "wos"."ISOVERDUE"
COUNT() returns and integer. So both the numerator and denominator of the percentage calculation, as written in the question, are integers. As it says in the documentation


  If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.


The solution is to cast one or other (or both) to a non-integer type. The rules for precedence are a bit complicated so you may need to fiddle around to get just what you want. Or you can write a second CAST to deliver the percentage as desired.