简体   繁体   English

SQL 值 = 0.5 或 0.0

[英]SQL value = 0.5 or 0.0

I have a floor question.我有一个地板问题。

(1) - (1) -

declare @value numeric(5,1),
set @value = 36.66,
select floor(2*@value)/2,
Answer= 36.5

But (2) -但是 (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)我需要答案 = 36.5 和用户 (2)

Thanks谢谢

/ (Division) (Transact-SQL) /(除)(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.除 datetime 和 smalldatetime 数据类型外,被除数可以是数字数据类型类别的任何一种数据类型的任何有效表达式。

divisor Is the numeric expression by which to divide the dividend. divisor是除以被除数的数值表达式。 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.除数可以是数字数据类型类别的任何一种数据类型的任何有效表达式,但 datetime 和 smalldatetime 数据类型除外。

Result Types Returns the data type of the argument with the higher precedence.结果类型返回具有较高优先级的参数的数据类型。 For more information, see Data Type Precedence (Transact-SQL).有关详细信息,请参阅数据类型优先级 (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.备注/ 运算符返回的实际值是第一个表达式除以第二个表达式的商。

110/3 - those are integer values and the result returned will be integer, so it automatically casts to integer, making the value 36 :) 110/3 - 这些是整数值,返回的结果将是整数,因此它会自动转换为整数,使值 36 :)

So in the second case your floor is doing nothing.所以在第二种情况下,你的floor什么也不做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM