• honza.mf (9/17/2010)


    tommyh (9/16/2010)


    Nice question. Though the explanation isnt entirely accurate. Its not rounded, its truncated.

    If the question had been, lets say

    declare @r decimal(5,2)

    set @r= round(5/3.2,1,3)

    select @r

    Then we would get 1.5 wheras a round would have given us 1.6 (change last parameter in Round to 0... or remove it all together).

    Right, the 3rd parameter of round is the most important one. It's value 3 is not typical but greater than zero.

    Just to be picky, it's not because the third parameter is greater than zero, but because it is not equal to zero. Here's the entry in BOL for SQL 2005:

    Syntax

    ROUND ( numeric_expression , length [ ,function ] )

    Arguments

    numeric_expression

    Is an expression of the exact numeric or approximate numeric data type category, except for the bit data type.

    length

    Is the precision to which numeric_expression is to be rounded. length must be tinyint, smallint, or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded on the left side of the decimal point, as specified by length.

    function

    Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.