SQL Server数据类型精度-Neo,什么是真实的? [英] SQL Server datatype precision - Neo, what is real?

查看:102
本文介绍了SQL Server数据类型精度-Neo,什么是真实的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Sever 2000 文档:

SQL Sever 2000 documentation:

是一个浮点数数据,具有 以下有效值:–3.40E + 38至-1.18E-38、0和1.18E- 38至3.40E +38.存储大小为 4字节.在SQL Server中,同义词 真正的是float(24).

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 文档:

SQL Server 2005 documentation:

ISO的real同义词是float(24).

The ISO synonym for real is float(24).

给定我正在阅读的内容,它说的精度为7,但我可以在数据库(SQL Server 2005)中输入的最大值为9(见下文),类似地表示为

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.

例如:0.180000082

Example: 0.180000082

real 的真正精度是多少?是否有可能会影响精度的配置选项(即:兼容模式)?

What is the true precision of real and are there configuration options(ie:compatibility modes) that can affect the precision?

推荐答案

您的答案在您链接的同一页面上:

Your answer is on that same page you linked:

对于FLOAT数据类型,n是用于以科学计数法存储尾数的位数

24个尾数位(大约)为7个十进制位精度(因为2 ^ 24〜= 10 ^ 7).

24 bits of mantissa gives you (approximately) 7 decimal digits of precision (because 2^24 ~= 10^7).

编辑添加:

请注意,每个人都在说大约"-这是有原因的:)

Notice that everyone keeps saying 'approximately' - this is for a reason :)

二进制浮点数和十进制文字不一定以直观的方式一起使用.有关背景知识,请阅读每个计算机科学家应了解的浮点运算法则.另请注意,说出" precision (精确度)的大约7个十进制数字"与存储超过7个有效数字的值并不矛盾!但是,这确实意味着该数据类型将无法区分例如0.180000082和0.180000083,因为它实际上没有存储以下任意一个的 exact 值:

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:

declare @f1 real
declare @f2 real

set @f1 = 0.180000082
set @f2 = 0.180000083

select @f1, @f2

select @f1 - @f2


------------- -------------
0.1800001     0.1800001

(1 row(s) affected)


-------------
0

(1 row(s) affected)


事实是realfloat(24)相同,后者是具有24位尾数的二进制浮点数,我不相信有办法改变这一点.如果您想存储精确的十进制数量,那么浮点类型通常不是一个好选择.


The fact is that real is the same as float(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.

这篇关于SQL Server数据类型精度-Neo,什么是真实的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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