Joh*_*ntu 2 t-sql sql-server datetime decimal rounding
在两个不同的sql服务器上,我运行以下查询:
declare @myDatetime as datetime = '2017-07-04 23:42:32.400'
select CAST(@myDatetime AS DECIMAL(20,5))
Run Code Online (Sandbox Code Playgroud)
我得到两个不同的结果:42918.98788和42918.98787
如果我转换为DECIMAL(20,6)它可以正常工作(42918.987875)但是我要说我需要把它放在十进制(20,5)中.
四舍五入时,我在哪里可以找到这种行为差异的根源?这是一个选项,可以在最后5点上下左右?它是一种场所,国际环境,整理还是其他?它是SQL的不同版本(12.0.5000.0 vs 13.0.4202.2)?
根据这个文件:https: //support.microsoft.com/en-us/help/4010261/sql-server-2016-improvements-in-handling-some-data-types-and-uncommon
微软已经对它如何处理一些"不常见"的转换做了一些改变:
SQL Server 2016 includes improvements to the precision of the following operations under compatibility level 130:
Uncommon data type conversions. These include the following:
float/integer to/from datetime/smalldatetime
real/float to/from numeric/money/smallmoney
float to real
Run Code Online (Sandbox Code Playgroud)
所以我怀疑在这种特定情况下,我们可能会看到不同的舍入.
| 归档时间: |
|
| 查看次数: |
51 次 |
| 最近记录: |