Full precision output of floating point types in 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)
但是,SQLCMD、osql 和查询分析器不支持.
However, SQLCMD, osql and the Query Analyzer do not.
SQLCMD -E -S server -Q"SELECT CONVERT(FLOAT, 1555.4899999999998)"
这篇关于SQL Server Management Studio 中浮点类型的全精度输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server Management Studio 中浮点类型的全精度输出
基础教程推荐
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
