So I am stuck on something that should be very easy, I'm hoping I'm making a simple syntax or type error that I just can't see, so I need some help.
I'm doing form validation in Laravel to make sure that if someone sends me JSON from the client with the price of an item as 0
that it won't then charge the customer 0
dollars but will instead return an error using Laravel's abort()
. My problem is even when the client-side totalCost
and the calculatedTotalCost
seem to be correct and identical when echoing them out, I still get the abort()
.
Part of my code is below:
$totalCost= str_replace("$","",$totalCost);
$totalCost = (float)$totalCost;
if($calculatedTotalCost != $totalCost){
abort(500, 'Your Order Cost Is Incorrect!'.$calculatedTotalCost." ".$totalCost);
return;
}
The thing is on the abort my response is:
Your Order Cost Is Incorrect!46.45 46.45
There it is, both 46.45
and I did the type conversion to a float so I don't understand why it throws the abort.