Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I round a number down to the nearest 10?

Tags:

rounding

mysql

In MySQL I would like to round numbers down to the nearest ten.

e.g. 812 -> 810, but also 819 -> 810

Using the ROUND function does not do the trick.

like image 861
merlot Avatar asked Mar 06 '17 17:03

merlot


1 Answers

I would divide by 10, do a floor() then multiply by 10 to get the proper int value. So in MySQL something like that :

SELECT FLOOR(Myattribute / 10) * 10;
like image 183
zoubida13 Avatar answered Sep 28 '22 03:09

zoubida13