rounding decimal to nearest integer value

  • how to round the nearest value after round of decimal and return integer. thanks.

    declare @data decimal(18,2)

    set @data = 5.55

    -- output

    select '5'

    set @data = 5.58

    -- output

    select '6'

  • sayedkhalid99 (6/28/2015)


    how to round the nearest value after round of decimal and return integer. thanks.

    declare @data decimal(18,2)

    set @data = 5.55

    -- output

    select '5'

    set @data = 5.58

    -- output

    select '6'

    Quick suggestion, use the ROUND function to round the decimal and the CONVERT to return an Integer.

    😎

    USE tempdb;

    GO

    SET NOCOUNT ON;

    declare @data decimal(18,2) = 5.55;

    SELECT CONVERT(INT,ROUND(@data,0,0),0);

  • sayedkhalid99 (6/28/2015)


    how to round the nearest value after round of decimal and return integer. thanks.

    declare @data decimal(18,2)

    set @data = 5.55

    -- output

    select '5'

    set @data = 5.58

    -- output

    select '6'

    I'm at a loss as to what rule you would use for rounding to get a value of 5 from 5.55, but a value of 6 from 5.58 ...

    The ROUND() function will take both of those values to 6 when rounded to zero decimal places. It would require a

    value of less than 5.5 to get a roundiing down to 5. FYI...

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Try this

    declare @a decimal(10,2), @b-2 decimal(10,2), @C decimal(6,0), @d decimal(6,0)

    select @a = 5.49 , @b-2 = 5.58

    select CAST(@a as decimal(10,0)),CAST(@b as decimal(10,0))

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

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