Round to 2 decimal

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neenaprasad
    New Member
    • Jan 2008
    • 13

    Round to 2 decimal

    I wrote an Sql as :-

    SELECT CAST(ROUND(SUM( CASE Question11 WHEN 1 THEN 1 ELSE 0 END), 0) AS numeric) * 100 /
    (SELECT COUNT(*)
    FROM CustomerFeedbac k
    WHERE (Question11 <> 0)) AS Expr1
    FROM CustomerFeedbac k

    The output is 66.6666........ ............... .

    I want the output to display in 2 decimal place ie., 66.66 or 66.67

    Can you help me....
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I think the problem is you are rounding then casting as numeric where you haven't specified a format.
    You probably don't need the CAST here. Change
    Code:
    SELECT CAST(ROUND(SUM(CASE Question11 WHEN 1 THEN 1 ELSE 0 END), 0) AS numeric)
    to
    Code:
    SELECT ROUND(SUM(CASE Question11 WHEN 1 THEN 1 ELSE 0 END),2)
    or specify a numeric format
    Code:
    SELECT CAST(ROUND(SUM(CASE Question11 WHEN 1 THEN 1 ELSE 0 END), 0) AS numeric(8,2)

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      If it's for display purposes, you can handle that in your front-end.

      -- CK

      Comment

      Working...