SQL Server Management Studio 中浮点类型的全精度输出
我的值 1555.4899999999998
以默认精度 (53) 存储在 float
列中.当我执行一个简单的 select
时,SSMS 会舍入输出而不是使用所有可用的精度打印它.它最近给我造成了一些问题,因为打印的值不能作为 float
文字来匹配实际存储的值.
I have the value 1555.4899999999998
stored in a float
column with default precision (53). When I do a simple select
, SSMS rounds the output instead of printing it with all available precision. It's caused some gotchas for me recently since the value printed doesn't work as a float
literal to match the actual stored value.
例如(请注意,这两个数字在默认的 float
中都有精确的表示),
For example (note that both of these numbers have an exact representation in the default float
),
declare @f1 float;
declare @f2 float;
set @f1 = 1555.49;
set @f2 = 1555.4899999999998;
select @f1, @f2;
select STR(@f1,30,15), STR(@f2,30,15);
输出:
1555.49 1555.49
1555.490000000000000 1555.489999999999800
在查询分析器中,第一个 select
输出:
In Query Analyzer, that first select
outputs:
1555.49 1555.4899999999998
这就是我想从 Management Studio 获得的行为.有没有办法防止 SSMS 在其结果显示中四舍五入?
That's the behavior I want to get from Management Studio. Is there a way to prevent SSMS from rounding in its result display?
推荐答案
没有.
SQL Server Management Studio 为显示目的对浮点值进行舍入;有一个连接建议改变此行为,但按设计"已关闭.(Microsoft Connect,Microsoft 软件的公共问题跟踪器已停用)
SQL Server Management Studio rounds floating point values for display purposes; there is a Connect suggestion to change this behavior, but it is closed "as By Design". (Microsoft Connect, a public issue tracker for Microsoft software has been retired)
但是,SQLCMD
、osql
和查询分析器不支持.
However, SQLCMD
, osql
and the Query Analyzer do not.
SQLCMD -E -S server -Q"SELECT CONVERT(FLOAT, 1555.4899999999998)"
相关文章