Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to round down to nearest integer in MySQL?

How would I round down to the nearest integer in MySQL?

Example: 12345.7344 rounds to 12345

mysql's round() function rounds up.

I don't know how long the values nor the decimal places will be, could be 10 digits with 4 decimal places, could be 2 digits with 7 decimal places.

like image 354
d-_-b Avatar asked Sep 11 '12 00:09

d-_-b


People also ask

How do you round to the nearest integer in MySQL?

ROUND() Function in MySQL. The ROUND() function in MySQL is used to round a number to a specified number of decimal places. If no specified number of decimal places is provided for round off, it rounds off the number to the nearest integer.

How do I round a number down in MySQL?

In MySQL, the FLOOR() function allows you to round a number down to the nearest integer. More specifically, it returns the largest integer not larger than its argument.

How do you round down to the nearest integer?

Rounding to the Nearest IntegerIf the digit in the tenths place is less than 5, then round down, which means the units digit remains the same; if the digit in the tenths place is 5 or greater, then round up, which means you should increase the unit digit by one.

How do you round to the nearest value in SQL?

Decimal data type value with positive LengthSELECT 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

Use FLOOR:

SELECT FLOOR(your_field) FROM your_table 
like image 179
Jocelyn Avatar answered Sep 20 '22 00:09

Jocelyn