Why does TSQL on Sql Server 2000 round decimals inconsistently?

风格不统一 提交于 2019-12-05 13:28:12

What is the data type of retail? I can't test this on SQL 2000, but on SQL 2008 R2, I see similar results if I use float.

float:         4.39 --> 2.195, rounds to 2.19 
               2.49 --> 1.245, rounds to 1.25

money:         4.39 --> 2.195, rounds to 2.20
               2.49 --> 1.245, rounds to 1.25

decimal(5,2):  4.39 --> 2.195, rounds to 2.20
               2.49 --> 1.245, rounds to 1.25

To show the approximation created by float, you can cast to decimal(20,19) and it becomes clear why it's rounding this way:

4.39 * 0.5 --> 2.1949999999999999000
2.49 * 0.5 --> 1.2450000000000001000

Take a look at some rounding methods here: SQL Server Rounding Methods bankers rounding is explained

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