celling or rounding
-
9 июня 2012 г. 23:34
how to get 5/2 = 2.5 but i wan to round to 3 ..how do i achieve?
Все ответы
-
9 июня 2012 г. 23:40
I would recommend to use the
CEILING ()
function if you always want to round off to the next higher integer - http://msdn.microsoft.com/en-us/library/ms189818.aspx
The FLOOR () function if you always want to round off to the previous lower integer - http://msdn.microsoft.com/en-us/library/ms178531.aspx
AND the ROUND() if you want a decimal result as per your precision requirements - http://msdn.microsoft.com/en-us/library/ms175003.aspx
in your case if you always want 5/2 = 3 , use the CEILING function.
Sanil Mhatre | Database Developer | MCTS | If you find my reply useful in any way, please vote it as helpful. If it has helped answer your question, please mark it as Answer. http://sqlwithsanil.com
- Изменено Sanil Mhatre 9 июня 2012 г. 23:41
-
9 июня 2012 г. 23:40
Regards,
Ahmed Ibrahim
SQL Server Setup Team
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
This can be beneficial to other community members reading the thread. -
9 июня 2012 г. 23:45SELECT CEILING(5/2) or SELECT ROUND(5/2 , 5) are not working
-
10 июня 2012 г. 1:04
can you try
select ROUND(5.0/2.0, 1)
or
select CAST(5 AS decimal (2,1)) / CAST(2 AS decimal(2,1))
Regards,
Ahmed Ibrahim
SQL Server Setup Team
This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" and "Vote as Helpful" on posts that help you.
This can be beneficial to other community members reading the thread.
- Изменено Ahmed Ibrahim - MSFTMicrosoft Employee 10 июня 2012 г. 1:13
- Предложено в качестве ответа Naomi NMicrosoft Community Contributor, Moderator 10 июня 2012 г. 3:09
-
10 июня 2012 г. 1:15
Hi There
Please try this one
select convert(int,round(convert(decimal(10,2),5)/2,0))
select CEILING(convert(decimal(10,2),5)/2)as number
Many Thanks
Syed Qazafi Anjum
Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.
- Изменено Syed Qazafi AnjumMicrosoft Community Contributor 10 июня 2012 г. 1:18
- Предложено в качестве ответа Aalam Rangi 10 июня 2012 г. 7:22
- Помечено в качестве ответа Dkuud 10 июня 2012 г. 18:15
-
10 июня 2012 г. 7:12
how to get 5/2 = 2.5 but i wan to round to 3 ..how do i achieve?
I don't think that you need to do the round for this as in T-SQL integer divided by integer return integer.
So for your case it is simple, Select 5/2 + 1 which is 3, no convertion and no rounding.
But I believe you must have a good reason to ask this question, just guess that you want odd number divided by 2 will return back value to be Number/2 + 1, so I think you might look for this:
Select Case when Number % 2 = 1 Then Number/2 + 1 Esle Number/2 End
From your_table
|
Blog: MSBICOE.com |
MCITP - BI, SQL Developer & DBA Hate to mislead others, if I'm wrong slap me. Thanks!
- Предложено в качестве ответа Aalam Rangi 10 июня 2012 г. 7:22
- Изменено Steven Wang - Shangzhou 10 июня 2012 г. 8:02
- Помечено в качестве ответа Dkuud 10 июня 2012 г. 18:15

