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 中浮点类型的全精度输出


基础教程推荐
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01