I have a floor question.
(1) -
declare @value numeric(5,1),
set @value = 36.66,
select floor(2*@value)/2,
Answer= 36.5
But (2) -
declare @value numeric(5,1),
set @value = 110/3,
select floor(2*@value)/2,
Answer = 36
I need the answer = 36.5 and user (2)
Thanks
CodePudding user response:
/ (Division) (Transact-SQL)
Arguments dividend Is the numeric expression to divide. dividend can be any valid expression of any one of the data types of the numeric data type category, except the datetime and smalldatetime data types.
divisor Is the numeric expression by which to divide the dividend. divisor can be any valid expression of any one of the data types of the numeric data type category, except the datetime and smalldatetime data types.
Result Types Returns the data type of the argument with the higher precedence. For more information, see Data Type Precedence (Transact-SQL).
If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated.
Remarks The actual value returned by the / operator is the quotient of the first expression divided by the second expression.
CodePudding user response:
110/3 - those are integer values and the result returned will be integer, so it automatically casts to integer, making the value 36 :)
So in the second case your floor
is doing nothing.