为什么SELECT 1/2返回0?


Answers:


29

它们是整数。

尝试:

select 1.0/2.0;

要么:

select CONVERT(NUMERIC,1)/CONVERT(NUMERIC,2);

14

首先,您将数字作为整数执行,但是其次,您还没有定义数字数据类型的精度和小数位数

尝试这个:

SELECT CONVERT(NUMERIC(5, 2), 1.0/2.0)

甚至

SELECT CONVERT(NUMERIC(5, 2), 1/2.0)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.