I have a function that casts and returns the following:
$price = (double)number_format(2.97, 5, '.', '');
But when doing the query through Laravel Eloquent like:
$query = \App\Models\CustomersPrices::where('price', $price)->exists();
I wasn't finding the price in database. After some digging I did the following:
DB::enableQueryLog();
$query = \App\Models\CustomersPrices::where('price', $price)->exists();
$sql = DB::getQueryLog();
\Log::error($sql);
And the result is:
array (
0 =>
array (
'query' => 'select exists(select * from `customers_prices` where `price` = ? ) as `exists`',
'bindings' =>
array (
0 => 2.970000000000000195399252334027551114559173583984375,
),
'time' => 1.560000000000000053290705182007513940334320068359375,
),
)
Why is this happening? Doing var_dump($price)
shows float(2.97)
.
What am I missing?