Theory
I have quite a comprehensive coordinates list (Latitude and Longitude to 7 decimal places), which I want to continually add to. In order to stop data duplication, for each coordinate that's trying to be be inputted, I want to check the database to see if the latitude and longitude exist, on the same row.
Check to see if coordinates exist
$coordinate = DB::table('coordinates')
->where('lat', '=', $geocode->getLatitude())
->where('lng', '=', $geocode->getLongitude())
->count();
Migration
Schema::create('coordinates', function(Blueprint $table)
{
$table->increments('id');
$table->float('lat', 10, 7);
$table->float('lng', 10, 7);
$table->timestamps();
});
When the user's address is converted, I have noticed that when dd()
the latitude variable, it comes out as:
float(53.7960957)
from the code dd($geocode->getLatitude());
When I try to add it afterwards to the database, by removing the dd()
, the actual decimal that's added into the database is 53.7960968
- A completely different location when we're talking about coordinates!
Why is the decimal changing from echoing on my screen, to adding to the database?
Do I need to convert it to a float before adding? How can I resolve this?