I have a calculation to be done in a query: ((28154/3745181) * 100)
, whose resultant value is .751739
which I want as 0.75
.
But when I try to do it in a query, I get 0
as shown below:
select ((28154/3745181) * 100) --Returns 0 as the result.
How can I get the desired 0.75
as the resultant?
You are doing integer arithmetic because your types are integer types.
select ((cast(28154 as float)/cast(3745181 as float)) * 100)
However you are obviously trying to get percentages so this is an alternative:
select((100 * 28154) / 3745181 )
I.e. do the multiplication first, then the division.