I'm trying to get the decimals of an operation:
SELECT CAST(22*100/148 AS FLOAT)
My result is 14 and I need it to be 14.86 as the result shows a calculator.
I'm trying to get the decimals of an operation:
SELECT CAST(22*100/148 AS FLOAT)
My result is 14 and I need it to be 14.86 as the result shows a calculator.
I suggest you do the splitter's cast:
SELECT 22*100/CAST(148 AS FLOAT)
But, the literals of the numbers are considered integers, so the final division will be an integer. Another possibility is to indicate a literal that does not lend itself to confusion:
SELECT 22*100/148.0
You can use convert
to get the result in the following way:
SELECT (CONVERT(FLOAT,22*100) / 148)
I'll also give you an example with cast
, it's a matter of using a syntax similar to your case, however we cassette the whole to FLOAT
before doing the division:
SELECT (CAST(22*100 AS FLOAT) / 148)
I hope it's your help.