Roger
Roger

Reputation: 2135

TSQL round to half decimals

I want to round to the nearest half decimals (geo coordinates) to do some data visualization. In t-sql, is there a built in function to round to half decimals (if that is the term). Examples of desired result:

    1.1 > 1.0
    1.4 > 1.5
    1.6 > 1.5
    1.9 > 2.0

Upvotes: 3

Views: 4851

Answers (1)

Guffa
Guffa

Reputation: 700152

Just multiply by 2, round, and divide by 2.

select round(1.1 * 2, 0) / 2 -- > 1.0
select round(1.4 * 2, 0) / 2 -- > 1.5
select round(1.6 * 2, 0) / 2 -- > 1.5
select round(1.9 * 2, 0) / 2 -- > 2.0

Round on MSDN

Upvotes: 12

Related Questions