Round to the integer part

  • Hi All,

    I encountered a data rounding problem.

    I want to rounded using such logic:

    3,4 = 3

    3,5 = 4

    3,9 = 4

    If I use ceiling I always receive 4, when floor then 3.

    Could you help me, please?

     

  • Look at the ROUND function

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

  • Hi David,

    I as well can execute it.

    For example , I have such value: round(0.57,0).

    When the number less 1 it doesn't work.

    As well I receive in this case decimal value...

  • christi1711 wrote:

    Hi David,

    I as well can execute it. For example , I have such value: round(0.57,0). When the number less 1 it doesn't work.

    As well I receive in this case decimal value...

    That is because 0.57 is treated as decimal(2,2) and when rounded to 1.00 will not fit decimal(2,2).

    You will need to cast 0.57 first to a specific decimal(p,2) such as

    SELECT ROUND(CAST(0.57 as decimal(3,2)),0)

    What is the datatype of the column/variable you are trying to round?

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

  • David,

    thanks a lot!

    It works

    Regards,

    Khrystyna

  • You're welcome and thanks for the feedback.

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

  • FYI - the cast by itself will round the value - so: Select cast(0.57 As decimal(3,0)) will return 1 (not 1.00 though).

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 7 posts - 1 through 6 (of 6 total)

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