Reputation: 103358
Both of the following queries will give me the same result, and I've seen both techniques being used in the past to ensure a decimal
data type is returned.
select CAST(5 as decimal(18,2))/2
select 5*1.0/2
Which method is best to use?
Why would people use *1.0
over casting? Is this just because its quicker to type?
Upvotes: 1
Views: 1302
Reputation: 239664
If you want to control the precision or scale of the result, then you'll have to use CAST
or CONVERT
. But I believe that if you just want "a decimal", then as you suggested, it's just quicker to type * 1.0
.
Upvotes: 3