# decimal 和 numeric (Transact-SQL)decimal and numeric (Transact-SQL)

## 引數Arguments

decimal[ ( p[ , s] ) ] 和 numeric[ ( p[ , s] ) ]decimal[ (p[ ,s] )] and numeric[ (p[ ,s] )]

p (有效位數)p (precision)

Informatica 只支援 16 個有效數字，無論指定的有效位數和小數位數為何。Informatica only supports 16 significant digits, regardless of the precision and scale specified.

s (小數位數)s (scale)

1 - 91 - 9 55
10-1910-19 99
20-2820-28 1313
29-3829-38 1717

Informatica (透過 SQL Server PDW Informatica Connector 連線) 只支援 16 個有效數字，無論指定的有效位數和小數位數為何。Informatica (connected through the SQL Server PDW Informatica Connector) only supports 16 significant digits, regardless of the precision and scale specified.

## 轉換 decimal 與 numeric 資料Converting decimal and numeric data

Transact-SQLTransact-SQL 陳述式中，會使用必要的最小有效位數與小數位數，自動將有小數點的常數轉換成 numeric 資料值。In Transact-SQLTransact-SQL statements, a constant with a decimal point is automatically converted into a numeric data value, using the minimum precision and scale necessary. 例如，常數 12.345 會轉換成有效位數 5、小數位數 3 的 numeric 值。For example, the constant 12.345 is converted into a numeric value with a precision of 5 and a scale of 3.

decimalnumeric 轉換成 floatreal 可能會導致有效位數的遺失。Converting from decimal or numeric to float or real can cause some loss of precision. intsmallinttinyintfloatrealmoney，或 smallmoney 轉換成 decimalnumeric 可能會導致溢位。Converting from int, smallint, tinyint, float, real, money, or smallmoney to either decimal or numeric can cause overflow.

SQL Server 2016 (13.x)SQL Server 2016 (13.x) 之前，float 值轉換至 decimalnumeric，就會限制為只有 17 個有效位數的值。Prior to SQL Server 2016 (13.x)SQL Server 2016 (13.x), conversion of float values to decimal or numeric is restricted to values of precision 17 digits only. 任何小於 5E-18 (當設定使用 5E-18 科學記號標記法或 0.0000000000000000050000000000000005 十進位標記法時) 的 float 值都會捨去為 0。Any float value less than 5E-18 (when set using either the scientific notation of 5E-18 or the decimal notation of 0.0000000000000000050000000000000005) rounds down to 0. 這不再是 SQL Server 2016 (13.x)SQL Server 2016 (13.x) 的限制。This is no longer a restriction as of SQL Server 2016 (13.x)SQL Server 2016 (13.x).

## 範例Examples

``````CREATE TABLE dbo.MyTable
(
MyDecimalColumn decimal(5,2)
,MyNumericColumn numeric(10,5)

);

GO
INSERT INTO dbo.MyTable VALUES (123, 12345.12);
GO
SELECT MyDecimalColumn, MyNumericColumn
FROM dbo.MyTable;

``````

``````MyDecimalColumn                         MyNumericColumn
--------------------------------------- ---------------------------------------
123.00                                  12345.12000

(1 row(s) affected)

``````