Code:
var_dump($prodCost);
$prodCost = (float)$prodCost;
var_dump($prodCost);
result:
string(5) "$4.57"
float(0)
What am I doing wrong here? I am looking for the result to be float(4.57).
The $-sign is not valid for numbers, PHP will break off after the first non-numeric char. Try this:
php > echo floatval(ltrim('$4.57', '$'));
4.57
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With