Reputation: 5056
I have this TSQL script:
declare @dcml decimal
declare @flt float
SELECT @dcml = 5/cast(4 AS float)
PRINT(@dcml) -- return 1
SELECT @flt = 5/cast(4 AS float)
PRINT(@flt) -- return 1.25
Why in the first case the result is rounded even with a decimal container for result?
Upvotes: 2
Views: 136
Reputation: 391316
Because by default, the number of digits that are stored after the decimal point is 0, and you haven't specified a value to override this.
See the MSDN documentation here.
To fix:
declare @dcml decimal(18,5)
This will store 5 digits after the decimal point.
Basically you had an integer type there.
Upvotes: 2