Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ROUND Function 1

Status
Not open for further replies.

Digga

Programmer
May 11, 2001
84
0
0
GB
Hi

Can someone tell me how to round a decimal datatype value up to the nearest .5 in MS SQL.

For example:

1.2 = 1.5
1.4 = 1.5
1.6 = 2.0
1.8 = 2.0

etc., etc.

Many thanks in advance.

Digga

Sharing Knowledge Saves Valuable Time!
 
declare @a decimal(10,2)
select @a = 1.34

SELECT ROUND(@a/.5,0) *.5

--or for two places

SELECT ROUND(@a/.5,1) *.5

--Note 1.2 will be rounded down
 
Hi Guys

Thanks for your responses.

Jamfool, thank you, I had tried this and it didn't meet my needs as I wanted to round up, but thanks anyway.

Terry, spot on mate, thank you very much.

Digga

Sharing Knowledge Saves Valuable Time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top