Consider this query:
WITH Scores (score)
AS
(
SELECT CAST(score AS INTEGER)
FROM (
VALUES (0),
(10),
(10)
) AS Scores (score)
)
SELECT AVG(CAST(score AS DECIMAL(19, 8))) AS precision_eight,
AVG(CAST(score AS DECIMAL(19, 7))) AS precision_seven,
AVG(CAST(score AS DECIMAL(19, 6))) AS precision_six,
AVG(CAST(score AS DECIMAL(19, 5))) AS precision_five,
AVG(CAST(score AS DECIMAL(19, 4))) AS precision_four
FROM Scores;
Results:
precision_eight | precision_seven | precision_six | precision_five | precision_four
6.66666666 | 6.6666666 | 6.666666 | 6.666666 | 6.666666
Why do I always get a minimum of six decimal places? Is this documented behaviour?
(I'm running SQL Server 2008)