numeric and int in sql server
Posted Chuck Lu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了numeric and int in sql server相关的知识,希望对你有一定的参考价值。
类型映射
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings
C#关键字
decimal
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/decimal
The decimal
keyword indicates a 128-bit data type.
Compared to other floating-point types, the decimal
type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.
The approximate range and precision for the decimal
type are shown in the following table.
取值范围(-7.9 x 1028 to 7.9 x 1028) / (100 to 1028)
精度28-29 significant digits
int
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/int
int
denotes an integral type that stores values according to the size and range shown in the following table.
取值范围-2,147,483,648 to 2,147,483,647
大小Signed 32-bit integer
SQL Server中
https://docs.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql
Numeric data types that have fixed precision and scale. Decimal and numeric are synonyms and can be used interchangeably.
decimal[ (p[ ,s] )] and numeric[ (p[ ,s] )]
Fixed
precision and scale numbers.
When maximum precision is used, valid values are from - 10^38 +1 through 10^38 - 1.
The ISO synonyms for decimal are dec and dec(p, s).
numeric is functionally equivalent to decimal.
p (precision)
The maximum total number of decimal digits that will 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.
s (scale)
The number of decimal digits that will be stored to the right of the decimal point.
This number is subtracted from p to determine the maximum number of digits to the left of the decimal point.
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.
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.
Example
numeric(18,2)的取值范围
最大9999999999999999.99 小数点右边两位数字,左边16位数字
以上是关于numeric and int in sql server的主要内容,如果未能解决你的问题,请参考以下文章
为啥 SQL Server 在将 int 转换为数据类型 numeric 时抛出算术溢出错误?
markdown WP-CLI-Launch-PHP-built-in-web-server-and-Start-MySQL-server.md
Difference between Char.IsDigit() and Char.IsNumber() in C#
Ambiguous method call. Both findViewById (int) in AppCompatActivity and findViewById (int) in Activi