Christophvh Christophvh - 6 months ago 15
PHP Question

Can't convert string to float in PHP - Laravel 5.2

I have a hidden field with a value. Since it's a hidden field my value is a string. In my database the value is stored as a decimal field with 2 point precision.


<tr class="grand-total">
<th>Total incl. 21% BTW:</th>
<?php $total = number_format($cartTotal, 2, ',', '') ?>
<td><strong class="grey-color">&euro;{{$total}}</strong></td>

<input type="hidden" name="total" value={{$total}}>


When my total is, for example, €10.95, I get €10.00.

Things I have tried:



floatval($request->total * 1.00)

But these all return €10.


You must provide a float number which uses a dot to separate integer from decimals, not a comma, so you must input 10.95 instead of 10,95.

Obviously you can use str_replace if you still want to use commas :

$myNumber = floatval(str_replace(',', '.', $myNumber));