Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql: How to get every rows that have more than a certain number of decimal after the dot

Tags:

sql

mysql

I have a table that contains float values.

table

+   id   |  value  |
+--------|---------|
+   1    | 19.22   |
+   2    | 32.333  |
+   3    | 1.2332  |
+   4    | 0.22334 |
+   5    | 4.55    |

I want to extract every row that contains more than 3 decimal after the dot.

The result I would expect is:

+   id   |  value  |
+--------|---------|
+   2    | 32.333  |
+   3    | 1.2332  |
+   4    | 0.22334 |
like image 389
yvoyer Avatar asked Nov 02 '10 18:11

yvoyer


People also ask

How do I limit the number of decimal places in MySQL?

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

How do I get 2 decimal places in MySQL?

FORMAT() function MySQL FORMAT() converts a number to a format like '#,###,###. ##' which is rounded upto the number of decimal places specified (in the second argument) and returns the result as a string.

How do I limit the number of decimal places 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 I remove extra numbers after decimal in SQL?

There are various methods to remove decimal values in SQL: Using ROUND() function: This function in SQL Server is used to round off a specified number to a specified decimal places. Using FLOOR() function: It returns the largest integer value that is less than or equal to a number.


2 Answers

Cast the value column as a varchar and use string comparison.

like image 182
dotariel Avatar answered Nov 12 '22 17:11

dotariel


This worked for me:

SELECT  *
FROM table
WHERE column <> ROUND (column,2)

or:

SELECT  *
FROM table
WHERE column <> CAST (column AS DECIMAL(36,2))
like image 6
JudgeDredd Avatar answered Nov 12 '22 18:11

JudgeDredd