SQL Server Management Studio中的浮点类型的完整精度输出 [英] Full precision output of floating point types in SQL Server Management Studio

查看:335
本文介绍了SQL Server Management Studio中的浮点类型的完整精度输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用默认精度(53)存储在 float 列中的值 1555.4899999999998 。当我做一个简单的选择时,SSMS对输出进行四舍五入,而不是用所有可用的精度进行打印。这是我最近引起一些陷阱,因为打印的值不能作为 float 文字来匹配实际存储的值。



例如(注意这两个数字在默认的 float 中都有一个确切的表示),

  declare @ f1 float 
declare @ f2 float
set @ f1 = 1555.49
set @ f2 = 1555.4899999999998
select @ f1,@ f2
选择STR(@ f1,30,15),STR(@ f2,30,15)



输出:

  1555.49 1555.49 
1555.490000000000000 1555.489999999999800

pre>

在查询分析器中,首先选择输出:

  1555.49 1555.4899999999998 

这就是我想得到的行为来自Management Studio。有没有一种方法可以防止SSMS在结果显示中四舍五入?



SQL Server Management Studio将浮点值舍入用于显示目的;有一个连接建议来改变这种行为 a>,但它是封闭的By Design。



然而, SQLCMD osql 和查询分析器不会。

  SQLCMD -E -S服务器-QSELECT CONVERT(FLOAT,1555.4899999999998)


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.

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)

Outputs:

1555.49 1555.49
1555.490000000000000    1555.489999999999800

In Query Analyzer, that first select outputs:

1555.49 1555.4899999999998

That's the behavior I want to get from Management Studio. Is there a way to prevent SSMS from rounding in its result display?

解决方案

No.

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".

However, SQLCMD, osql and the Query Analyzer do not.

SQLCMD -E -S server -Q"SELECT CONVERT(FLOAT, 1555.4899999999998)"

这篇关于SQL Server Management Studio中的浮点类型的完整精度输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆