SQL Server 数据类型 float, real, money, decimal, numeric

Float and Real 

Approximate-number data types for use with floating point numeric data. Floating point data is approximate; therefore, not all values in the data type range can be represented exactly. The ISO synonym for real is float(24).

 
Data typeRangeStorage

float

- 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308

Depends on the value of n

real

- 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 38

4 Byt

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 valuePrecisionStorage size

1-24

7 digits

4 bytes

25-53

15 digits

8 bytes

 

 

Decimal and Numeric

Numeric data types that have fixed precision and scale.

(p, s)] and numeric(p, s)]

are dec and dec(ps)numeric is functionally equivalent to decimal.

 

(scale)

. Scale can be specified only if precision is specified. The default scale is 0; therefore, 0 <= s <= p. Maximum storage sizes vary, based on the precision.

 

decimalFixed precision and scale numbers. When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1. The ISO synonyms for decimalp (precision) The maximum total number of decimal digits that can be stored, both to the left and to the right of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.The maximum number of decimal digits that can be stored to the right of the decimal point. Scale must be a value from 0 through p

 

Money and SmallMoney

Data types that represent monetary or currency values.

The money and smallmoney data types are accurate to a ten-thousandth of the monetary units that they represent.
Data type   RangeStorage

money

 

-922,337,203,685,477.5808 to 922,337,203,685,477.5807

8 bytes

smallmoney

 

- 214,748.3648 to 214,748.3647

4 bytes

 

 

FLOAT   类型表示浮点数(非精确数),可以接收以科学记数法表示的浮点数。FLOAT   类型比较特殊,定义时甚至可以给它指定精度。在实际应用中应该尽量避免使用
FLOAT作为等于或者不等于条件中,在大于或者小于条件中使用没有问题。
钱相关的建议使用money数据类型 
decimal建议在数据较大,或要求精度较高,或对计算结果进行精度控制时使用。decimal和numeric基本没有什么不同。
posted @   qanholas  阅读(1717)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· .NET周刊【3月第1期 2025-03-02】
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
点击右上角即可分享
微信分享提示