June 18, 2004 at 8:38 am
I am getting an average in a group by. The number stored as an int. It is currently rounding down. Can I have it round up? If so how?
Thanks
DavidCL
June 18, 2004 at 8:53 am
Is it really rounding down? Integers don't have decimal places so:
1.23 as an integer will be 1
it just drops the decimals.
Suggestion: CONVERT or CAST the integers to DECIMAL, then find the average. Leave the result as a DECIMAL or round the result up and CONVERT or CAST it back to an integer.
-SQLBill
June 18, 2004 at 10:04 am
Here is an example.
(174 + 231)/2=202.5
The users want this represented as 203. If I take the 202.5 and convert it to int it simply drops of the .5 and the result is 202.
Is there a clean way to get 202.5 converted to an int with a result of 203?
June 18, 2004 at 10:13 am
SELECT CEILING(CAST((174 + 231) AS DECIMAL) /2)
This should work for you
Good Hunting!
AJ Ahrens
webmaster@kritter.net
June 19, 2004 at 10:17 am
Thanks allot AJ! That is exactly what I was needing.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply