SQL Server 2000 Integer truncating

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 04:28:23

Under integer division 220/30 = 7 and 99/100 = 0 (note truncation not rounding)

Use non integers to avoid this. e.g. Select 30 * (220/30.0)

Or you can use an explicit cast

Select 30 * (220/cast (30 as float))

The one in the parentheses, is always evaluated first, but since the machine logic you are using integer, in that case, the result of the division is 7, wich you multiply by 30, gives you 210

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!