SQL Server,除法返回零 [英] SQL Server, division returns zero
本文介绍了SQL Server,除法返回零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我在示例中使用的代码:
Here is the code I'm using in the example:
PRINT @set1
PRINT @set2
SET @weight= @set1 / @set2;
PRINT @weight
结果如下:
47
638
0
我想知道为什么它返回 0
而不是 0,073667712
I would like to know why it's returning 0
instead of 0,073667712
推荐答案
要么将 set1 和 set2 声明为浮点数而不是整数,要么将它们强制转换为浮点数作为计算的一部分:
Either declare set1 and set2 as floats instead of integers or cast them to floats as part of the calculation:
SET @weight= CAST(@set1 AS float) / CAST(@set2 AS float);
这篇关于SQL Server,除法返回零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文