SQL Server的小数数值类型(float 和 decimal)用法

您所在的位置:网站首页 sql中min是什么意思 SQL Server的小数数值类型(float 和 decimal)用法

SQL Server的小数数值类型(float 和 decimal)用法

2023-05-15 08:19| 来源: 网络整理| 查看: 265

在SQL Server中,小数数值实际上只有两种数据类型:float 和 decimal。double precision 整体是数据类型,等价于 float(53),real等价于float(24),应该避免在程序中直接使用 double precision 和 real,而是用 float 代替。numeric 和 decimal是同义词。

float是近似数值,存在精度缺失,Decimal是精确数值,不存在精度损失。当数值不允许精度丢失时,使用 decimal数据类型存储。在计算小数的除法时,SQL Server 内部隐式升级数据类型,根据小数数值的数据类型,就近向float(24) 或float(53)转换。

一:近似数值,存在精度损失

1,float 表示近似数值

float数据类型的默认类型是float(53),占用8bytes,实际上,float 只能表示两种类型float(53) 和 float(24),分别占用 4Bytes 和 8Bytes。

float [ (n) ] 

Where n is the number of bits that are used to store the mantissa of the float number in scientific notation and, therefore, dictates the precision and storage size. If n is specified, it must be a value between 1 and 53. The default value of n is 53.

 

n value 

Precision 

Storage size

1-24    

7 digits  

4 bytes 

25-53   

15 digits

8 bytes    

Note:SQL Server treats n as one of two possible values. If 1


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3