Differences among DECIMAL/NUMERIC, FLOAT and REAL data types.
DECIMAL/
NUMERIC
|
FLOAT
|
REAL
|
||||||||||||||||||||
Bytes
|
5 bytes - 17 bytes
Maximum storage
sizes vary, based on the precision
|
4 bytes to 8 bytes
depends on nvvalue
|
8 bytes
|
|||||||||||||||||||
Minimum Value
|
- 10^38 +1
|
- 1.79E+308 to -2.23E-308, 0
|
- 3.40E + 38 to -1.18E - 38, 0
|
|||||||||||||||||||
Maximum Value
|
10^38 - 1
|
2.23E-308 to 1.79E+308
|
1.18E - 38 to 3.40E + 38
|
|||||||||||||||||||
Max Length
|
38 digits
The default precision is 18.
|
|||||||||||||||||||||
Format
|
DECIMAL(p)
DECIMAL(p,s)
p- precision
s- scale
|
FLOAT(s)
|
REAL
|
|||||||||||||||||||
Example
|
DECLARE @Decimal DECIMAL(38) = 92233720368547758079223372036854775807
SELECT @Decimal
DECLARE @Decimal DECIMAL(38,2) =
122337203685477580792233720368547758.07
SELECT @Decimal
DECLARE @Decimal DECIMAL(38,3) =
12233720368547758079223372036854775.807
SELECT @Decimal
DECLARE @Numeric NUMERIC(38) = 92233720368547758079223372036854775807
SELECT @Numeric
DECLARE @Numeric NUMERIC(38,2) =
122337203685477580792233720368547758.07
SELECT @Numeric
DECLARE @Numeric NUMERIC(38,3) =
12233720368547758079223372036854775.807
SELECT @Numeric
54775 – Unit
. – Decimal point
807 - Mantissa
|
DECLARE @Float FLOAT(53) = 92233720368547758079223372036854775807
SELECT @Float
DECLARE @Float FLOAT(1) = 922337.47
PRINT @Float
OUTPUT: 922338
DECLARE @Float FLOAT(1) = 922337.46
PRINT @Float
OUTPUT: 922337
|
DECLARE @Real REAL = 92233720368547758079223372036854775807
SELECT @Real
DECLARE @Real REAL = 922337.47
PRINT @Real
OUTPUT: 922338
DECLARE @Real REAL = 922337.46
PRINT @Real
OUTPUT: 922338
|
No comments:
Post a Comment