Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select numbers with more than 4 decimal places

I have a SQL table with one float column populated with values like these:

  1.4313
  3.35
  2.55467
  6.22456
  3.325

I need to select rows containing only values with more than 4 decimals. In this case, the select must return:

2.55467
6.22456

Ideas? Thanks!

This is what I have tried so far

select * 
from table 
where CAST(LATITUDE AS DECIMAL(10,5)) - LATITUDE = 0
like image 777
BernieSF Avatar asked Sep 08 '15 16:09

BernieSF


People also ask

How do I limit to 4 decimal places in Excel?

Select the cells that you want to format. On the Home tab, click Increase Decimal or Decrease Decimal to show more or fewer digits after the decimal point.

How do I get 4 decimal places in SQL?

SQL Server ROUND() Function The ROUND() function rounds a number to a specified number of decimal places. Tip: Also look at the FLOOR() and CEILING() functions.

What does to 4 decimal places mean?

1 decimal place (tenths) 2 decimal places (hundredths) 3 decimal places (thousandths) 4 decimal places (ten-thousandths)


2 Answers

DECLARE @tbl TABLE (val float)
INSERT INTO @tbl SELECT 1234.567
INSERT INTO @tbl SELECT 1234.5678
INSERT INTO @tbl SELECT -1234.5678
INSERT INTO @tbl SELECT 1234.56789

SELECT *
from @tbl
where (((val*10000) - CONVERT(INT,(val*10000))) <> 0)
like image 127
UnhandledExcepSean Avatar answered Sep 19 '22 23:09

UnhandledExcepSean


Why cant we make it simple by this query:-

SELECT * FROM table WHERE val LIKE '%.____%'

This selects what we want

like image 25
Alif Noushad Avatar answered Sep 19 '22 23:09

Alif Noushad