Reputation: 4915
What am I missing here?
select cast ( ( cast (100 * 39 as decimal ) / 41) as decimal(5,2))
gives a result of 95.12
but
declare @percent decimal
set @percent = cast ( ( cast (100 * 39 as decimal ) / 41) as decimal(5,2))
select @percent
gives a result of 95
What happened to the two 2 decimal points and how do I get them back into my variable?
Upvotes: 1
Views: 1287
Reputation:
DECIMAL
on its own does not have any decimal places (it's actually DECIMAL(18,0)
). You need to specify precision and scale, e.g.
DECLARE @percent DECIMAL(5,2);
SET @percent = 1.0 * (100 * 39) / 41;
SELECT @percent;
Upvotes: 7