SQL Server Management Studio 中浮点类型的全精度输出

Full precision output of floating point types in SQL Server Management Studio(SQL Server Management Studio 中浮点类型的全精度输出)
本文介绍了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)

但是,SQLCMDosql 和查询分析器不支持.

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

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

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)