SQL Server 数据类型精度 - Neo,什么是真实的?
SQL Sever 2000 文档:
是浮点数数据 以下有效值:–3.40E + 38 至 -1.18E - 38、0 和 1.18E - 38 到 3.40E + 38。存储大小为 4字节。在 SQL Server 中,同义词 真实的是 float(24)。
SQL Server 2005 文档:
实数的 ISO 同义词是 float(24)。
编辑: 鉴于我正在阅读的内容,它表示精度为 7,但我可以在我的数据库(SQL Server 2005)中输入最多 9,请参见下文,如类似所述 此处问题号。 7.
示例:0.180000082
real 的真实精度是多少?是否有配置选项(即:兼容模式)会影响精度?
SQL Sever 2000 documentation:
Is a floating point number data with
the following valid values: –3.40E +
38 through -1.18E - 38, 0 and 1.18E -
38 through 3.40E + 38. Storage size is
4 bytes. In SQL Server, the synonym
for real is float(24).
SQL Server 2005 documentation:
The ISO synonym for real is float(24).
EDIT:
Given what I am reading it says the precision is 7 but I can enter in my database(SQL Server 2005) max of 9 see below, as similarly stated here question no. 7.
Example: 0.180000082
What is the true precision of real and are there configuration options(ie:compatibility modes) that can affect the precision?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的答案位于您链接的同一页面上:
位尾数为您提供(大约)7 个十进制位数的精度(因为2^24 ~= 10^7)。
编辑添加:
请注意,每个人都一直说“大约” - 这是有原因的:)
二进制浮点数和十进制文字不一定以直观的方式一起发挥作用。有关背景知识,请阅读每个计算机科学家应该了解的浮点运算知识。另请注意,“大约 7 位十进制数字的精度”与能够存储超过 7 位有效数字的值并不矛盾!然而,这确实意味着该数据类型将无法区分 0.180000082 和 0.180000083,因为它实际上并未存储其中任何一个的精确值:
事实是
real 与 float(24) 相同,是一个带有 24 位尾数的二进制浮点数,我不相信有办法改变它。如果您想存储精确的十进制数量,浮点类型通常不是一个好的选择。
Your answer is on that same page you linked:
24 bits of mantissa gives you (approximately) 7 decimal digits of precision (because 2^24 ~= 10^7).
edit to add:
Notice that everyone keeps saying 'approximately' - this is for a reason :)
Binary floating point numbers and decimal literals do not necessarily play together in an intuitive manner. For background read What Every Computer Scientist Should Know About Floating-Point Arithmetic. Also note that saying 'approximately 7 decimal digits of precision' is not incompatible with being able to store a value with more than 7 significant figures! It does mean however that this datatype will be unable to distinguish between 0.180000082 and 0.180000083, for example, because it isn't actually storing the exact value of either:
The fact is that
real
is the same asfloat(24)
, a binary floating point number with 24 bits of mantissa, and I don't believe there's a way to change this. Floating-point types are in general not a good choice if you want to store exact decimal quantities.您混淆了二进制(以 2 为基数)精度与十进制(以 10 为基数)精度。 24 位提供大约 7 位十进制数字。
You are confusing binary (base 2) precision with decimal (base 10) precision. 24 bits gives you approximately 7 decimal digits.
SQL Server 使用 4 字节或 8 字节来存储非十进制浮点数。
如果指定实数或 float<1> 范围内的任何值为了实现 float<24>,SQL Server 使用 float<24>内部。如果您使用 float 或 float<25> 范围内的任何内容,浮动<53> (限制),它使用 float<53>这也称为双精度。
SQL Server 2005 中浮点的 MSDN 文档位于:浮点和实数 (Transact-SQL )
如果您有特定的精度需求,请考虑使用十进制,它提供可配置的精度和小数位数:十进制和数字 (Transact-SQL)
SQL Server uses either 4 bytes or 8 bytes to store non-decimal floating point numbers.
If you specify real or any value in the range float<1> to float<24>, SQL server uses float<24> internally. If you use float or anything in the range float<25> to float<53> (the limit), it uses float<53> which is otherwise known as double precision.
MSDN documentation for float in SQL Server 2005 is here: float and real (Transact-SQL)
If you have a specific precision need, look instead at using decimal, which provides configurable precision and scale: decimal and numeric (Transact-SQL)