Convert int a float SQL

1

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.

    
asked by ARR 30.07.2018 в 18:00
source

2 answers

3

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
    
answered by 30.07.2018 / 18:04
source
1

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.

    
answered by 30.07.2018 в 18:08