Operation to get SQL percentage

0

I have the following query:

SELECT (CONVERT(FLOAT,22*100) / 148)

With it I get a percentage = 14.8648648648649

This percentage I have to show in my web application but in the following way, percentage = 14.86, only showing the last two decimals.

    
asked by ARR 30.07.2018 в 21:56
source

2 answers

2

You can use CAST , to convert it to numeric type ( numeric ) with only two (2) decimal places.

SELECT CAST((CONVERT(FLOAT,22*100) / 148) as numeric(36,2))
  

as numeric (x, 2), with x < = 38

Alternative:

ROUND( valorARedondear ,2) , but could return more than 2 decimals, depending on the data type if you use parameters obtained with a query .

    
answered by 30.07.2018 / 22:14
source
0

with the function ROUND(numero, decimal) you can round the value, it would be like this

SELECT (ROUND(CONVERT(FLOAT,22*100) / 148), 2)

I hope you serve ReNiceCode ...

    
answered by 30.07.2018 в 22:10