Run this script in SQL Server (My version is SQL Server 2016):
DECLARE @num1 DECIMAL(20,7)
DECLARE @num2 DECIMAL(20,7)
SET @num1 = 0.0000005
SET @num2 = 1.0
SELECT @num1 * @num2 AS Result
Result:
Result
---------------------------------------
0.00000050000
The result is 0.00000050000 in scale DECIMAL(X,11)
Now, if we change the script as follow:
DECLARE @num1 DECIMAL(21,7)
DECLARE @num2 DECIMAL(20,7)
SET @num1 = 0.0000005
SET @num2 = 1.0
SELECT @num1 * @num2 AS Result
Result:
Result
---------------------------------------
0.0000005000
You can see the result is 0.0000005000, it seems like the scale was reduced as DECIMAL(X,10)
Continue to increase the precision of @num1:
DECLARE @num1 DECIMAL(22,7)
DECLARE @num2 DECIMAL(20,7)
SET @num1 = 0.0000005
SET @num2 = 1.0
SELECT @num1 * @num2 AS Result
Result:
Result
---------------------------------------
0.000000500
The result is 0.000000500 now, it seems like the scale was reduced as DECIMAL(X,9)
I want to ask what the exact precision and scale after two DECIMAL numeric calculated is. It seems like there will be serious precision loss, if we multiplied two DECIMAL numeric. The following script will give totally wrong result due to precision loss, which will round fraction that exceeds scale of the result.
DECLARE @num1 DECIMAL(25,7)
DECLARE @num2 DECIMAL(20,7)
DECLARE @num3 DECIMAL(25,7)
DECLARE @num4 DECIMAL(20,7)
SET @num1 = 0.0000005
SET @num2 = 1.0
SET @num3 = 0.0000004
SET @num4 = 1.0
SELECT @num1 * @num2 AS Result1, @num3 * @num4 AS Result2
Result:
Result1 Result2
--------------------------------------- ---------------------------------------
0.000001 0.000000