Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to round numbers in sql
but there 's 1 condition with fraction
for example

declare @x float

select @x=34.44 --> in this is case i want @x=34
select @x=34.6 --> in this is case i want @x=35
select @x=34.5--> in this is case i want @x=34.5

meaning
if the fraction is less than 50% then work like floor function
if the fraction is greater thqn 50% then work like ceiling function
if the fraction is equl 50% do nothing

so i need help in that
Posted

SQL
select (case when @x - floor(@x) < 0.5 then floor(@x) when @x - floor(@x) > 0.5 then ceiling(@x) else @x end)
 
Share this answer
 
Comments
Abhinav S 25-Oct-11 0:35am    
A working solution. 5.
Prerak Patel 25-Oct-11 2:09am    
Thanks. OP already put all these things in words. I just did 'English - SQL' ;)
Did you try round(DENOMINATION, 2)?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900