Using LIKE to match floats when Rounding is not wanted

 ̄綄美尐妖づ 提交于 2019-12-06 10:29:10

If you do not want to change from using LIKE. You could cast the float to a decimal and then to an nvarchar, this should stop the rounding issue.

SELECT COUNT(*) FROM dbo.StartCoord 
WHERE CAST(CAST(StartLatitude  as DECIMAL(12,6)) as nvarchar(20)) LIKE '12.817%' 
AND   CAST(CAST(StartLongitude as DECIMAL(12,6)) as nvarchar(20)) LIKE '12.819%'

I have assumed 6 decimal places is all you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!