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 中浮点类型的全精度输出
基础教程推荐
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
