SQL - Rounding off to 2 decimal places

user656523 picture user656523 · Apr 30, 2012 · Viewed 883.6k times · Source

I need to convert minutes to hours, rounded off to 2 decimal places.I also need to display only up to 2 numbers after the decimal point. So if I have minutes as 650.Then hours should be 10.83

Here's what I have so far:

Select round(Minutes/60.0,2) from ....

But in this case, if my minutes is, say,630 - hours is 10.5000000. But I want it as 10.50 only(after rounding). How do I achieve this?

Answer

u07ch picture u07ch · Apr 30, 2012

Could you not cast your result as numeric(x,2)? Where x <= 38

select 
    round(630/60.0,2), 
    cast(round(630/60.0,2) as numeric(36,2))

Returns

10.500000   10.50