Rounding

  • I'm trying to ROUND to 2 Decimal Places. The query is below. The Value Column is a MONEY DataType!

    When I execute the query below, it doesn't ROUND to 2 Decimal Places. THe result is the same, it has 4 digits after the decimal!

    Is there a trick to this?

    SELECT AccountID, ROUND(SUM(CASE WHEN Value < 0 THEN Value ELSE 0 END), 2) AS 'Debit',

        ROUND(SUM(CASE WHEN Value > 0 THEN Value ELSE 0 END), 2) AS 'Credit'

    FROM Invoices

    GROUP BY AccountID


    Kindest Regards,

  • Use convert to truncate.

  • Conevrt to what DataType?


    Kindest Regards,

  • Money will always be displayed with four decimal places whether rounded or not

    12.3456

    will be 12.3456

    or 12.3500 when rounded to 2 decimal places

    if you want the values to have two decimal places cast them to decimal

    SELECT AccountID,

     CAST(ROUND(SUM(CASE WHEN Value < 0 THEN Value ELSE 0 END), 2) AS decimal(9,2)) AS 'Debit',

     CAST(ROUND(SUM(CASE WHEN Value > 0 THEN Value ELSE 0 END), 2) AS decimal(9,2)) AS 'Credit'

    FROM #Invoices

    GROUP BY AccountID

    Far away is close at hand in the images of elsewhere.
    Anon.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply