简体   繁体   中英

How to compare a double value to a decimal from database and if they are alike, then return true

Example:

Database latitude value: 33.3360705

location from android device latitude value: 33.33607

These are technically NOT the same, BUT the difference is so little that I would like to consider them the same.

How would I do that? :)

Thanks.

Just use ROUND in MySQL when getting the value from the database. The following will round to 5 decimal places (which matches your android device value):

SELECT ROUND(myValue, 5) 
FROM myTable

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM