-1

I am developing one API which is responsible for searching with float values like 99.99 or 67.00.....,Below query should get the data if we enter 9999 inorder to 99.99,but i need to show results if the user search with the 99.99 only..

$searchBooks=Books::where("price",$price)->get();
Sai Tarun
  • 569
  • 4
  • 14

1 Answers1

0

testing for exact float values is a bad idea since floating point precision is not enough for equality.

$searchBooks=Books::whereRaw("abs(price-{$price})<0.0001")->get();

see more details in this question.

OMR
  • 11,736
  • 5
  • 20
  • 35