DECIMAL LÀ GÌ

Trong bài viết này

Applies to:

*
SQL Server (all supported versions)
*
Azure SQL Database
*
Azure SQL Managed Instance
*
Azure Synapse Analytics
*
Analytics Platform System (PDW)

Numeric data types that have sầu fixed precision và scale. Decimal and numeric are synonyms và can be used interchangeably.

Bạn đang xem: Decimal là gì

Arguments

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 identical khổng lồ decimal.

p (precision)The maximum total number of decimal digits to be stored. This number includes both the left & the right sides of the decimal point. The precision must be a value from 1 through the maximum precision of 38. The default precision is 18.


Note

Informatica only supports 16 significant digits, regardless of the precision và scale specified.


s (scale)The number of decimal digits that are stored lớn 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. Scale must be a value from 0 through p, and can only be specified if precision is specified. The mặc định scale is 0 & so 0 PrecisionStorage bytes1 - 9510-19920-281329-3817

Note

Informatica (connected through the SQL Server PDW Informatica Connector) only supports 16 significant digits, regardless of the precision và scale specified.


Converting decimal và numeric data

For decimalnumeric data types, SQL Server considers each combination of precision và scale as a different data type. For example, decimal(5,5) & decimal(5,0) are considered different data types.

Xem thêm: Vai Trò Của Thiên Nhiên Bao Gồm Những Gì ? Theo Em,Vì Sao Thiên Nhiên Là Gì

In Transact-Squốc lộ statements, a constant with a decimal point is automatically converted inlớn a numeric data value, using the minimum precision and scale necessary. For example, the constant 12.345 is converted into lớn a numeric value with a precision of 5 and a scale of 3.

Converting from decimal or numeric to lớn float or real can cause some loss of precision. Converting from int, smallint, tinyint, float, real, money, or smallmoney lớn either decimal or numeric can cause overflow.

By mặc định, Squốc lộ Server uses rounding when converting a number to a decimal or numeric value with a lower precision & scale. Conversely, if the SET ARITHABORT option is ON, SQL Server raises an error when overflow occurs. Loss of only precision and scale isn"t sufficient to raise an error.

Examples

The following example creates a table using the decimal and numeric data types. Values are inserted into each column. The results are returned by using a SELECT statement.

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; Here is the result set.

MyDecimalColumn MyNumericColumn --------------------------------------- --------------------------------------- 123.00 12345.12000 (1 row(s) affected)

See also

ALTER TABLE (Transact-SQL)CAST và CONVERT (Transact-SQL)CREATE TABLE (Transact-SQL)DECLARE