Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round to .5 or 1.0 in SQL

Tags:

I'm looking to round values like

2.3913 -> 2.5

4.6667 -> 4.5

2.11 -> 2

How can I manage this in SQL?

Thanks

like image 928
Sandeep Bansal Avatar asked Mar 26 '12 14:03

Sandeep Bansal


People also ask

How do I ROUND to the nearest 0.5 in SQL?

SQL Server ROUND() Function The ROUND() function rounds a number to a specified number of decimal places.

How do you ROUND to a specific decimal in SQL?

If you'd like to round a floating-point number to a specific number of decimal places in SQL, use the ROUND function. The first argument of this function is the column whose values you want to round; the second argument is optional and denotes the number of places to which you want to round.

How do you ROUND to the nearest value in SQL?

SELECT ROUND(@value, 1); SELECT ROUND(@value, 2); SELECT ROUND(@value, 3); In this example, we can see that with decimal values round up to the nearest value as per the length.


1 Answers

SELECT ROUND(2.2 * 2, 0) / 2  

gets you to the nearest .5

like image 191
Paul Avatar answered Sep 30 '22 05:09

Paul