Click here to Skip to main content
15,892,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Round up and Round-down value ??

I have value 3.74 Which should be round-down to 3.50 And
value 3.76 ,which should be round-up to 4.00
Posted

1 solution

SQL
--pass your value to @yourvalue and execute the query

declare @yourvalue decimal(4,2)
select @yourvalue = 3.75
declare @roundpart int
set @roundpart=floor(@yourvalue)
declare @des int
set @des =PARSENAME(@yourvalue,1)
if(@des>=75)
begin
 set @yourvalue= convert(decimal(4,2) ,@roundpart+1)
PRINT  @yourvalue
end
else
begin
set @yourvalue=convert(decimal(4,2), convert(varchar(10),@roundpart)+'.50')
print	@yourvalue
end
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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