Christophvh Christophvh - 1 year ago 102
PHP Question

Can't convert string to float 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 my value is stored as a decimal field with 2 precision.

my view

<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 e.g. €10,95 i get €10.00

Things i tried:



floatval($request->total * 1.00)

But these all return €10 .

Answer Source

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));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download