I have a table that contains float values.
+ 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.
+ id | value |
+--------|---------|
+ 2 | 32.333 |
+ 3 | 1.2332 |
+ 4 | 0.22334 |
The ROUND() function rounds a number to a specified number of decimal places.
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.
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.
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.
Cast the value
column as a varchar
and use string comparison.
This worked for me:
SELECT *
FROM table
WHERE column <> ROUND (column,2)
or:
SELECT *
FROM table
WHERE column <> CAST (column AS DECIMAL(36,2))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With