SQL Server的浮点数据类型的理解 [英] SQL Server float data type understanding

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

问题描述

https://msdn.microsoft。 COM / EN-US /库/ ms173773%28V = sql.110%29.aspx



在我插入值( 0.12346789123456789123456789)例如,有一个float类型列的表,我查询并取回 0.1234567891234568 包含 17 数字。我有三个问题。




  1. 我怎样才能回来跟踪输入和输出的二进制表示?该文件称,它使用53位为默认值。我使用SQL Server Management Studio中,我不知道如何我列的类型声明中指定 N 值。


  2. 17 不包含在文档中,我想知道它从何而来。


  3. 在或大或小端系统,我想知道如何这样的输入处理,转换成在低级别字节的系统输出。如果有人知道一个解释,我会心存感激。



解决方案

  DECLARE @i浮= 0.1234567890123456789123456789 
选择@i

0.123456789012346

这有15位;以及




请注意,首先 0 不计算在内。




  DECLARE @i浮= 123456.1234567890123456789123456789 
选择@i

123456.123456789

也有15位。



这是记录这里 的是精度为15位。


https://msdn.microsoft.com/en-us/library/ms173773%28v=sql.110%29.aspx

After I insert a value (0.12346789123456789123456789) for example in the table that has a float type column, I query and get back 0.1234567891234568 which contains 17 digits. I have 3 questions

  1. How can I back track the binary representation of the input and output ? The document says it uses 53 bits as default. I am using SQL Server Management Studio and I don't know how to specify n value during declaration of my column type.

  2. The number 17 isn't included in the document, I wish to know where it comes from.

  3. In Big or Little Endian systems, I'd like to know how such an input is treated and translated into the output at the low-level byte system. If anyone knows an explanation, I would be thankful.

解决方案

DECLARE @i float = 0.1234567890123456789123456789
SELECT @i

0.123456789012346

That has 15 digits; and

Note that first 0 is not counted.

DECLARE @i float = 123456.1234567890123456789123456789
SELECT @i

123456.123456789

Also has 15 digits.

That is documented here that Precision is 15 digits

这篇关于SQL Server的浮点数据类型的理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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