I have a string like this:
$price = "15.50";
And I would like to multiply it. Ex:
$price*$amount;
I tried something like this:
$Total = floatval($price)*$amount;
But I always get "30" as return. How can I code to get "31.00"?
Thanks a lot.
Try this...
$fltAmount = floatval($amount);
$fltPrice = floatval($price);
$Total = $fltAmount*$fltPrice
I found the answer here! http://www.php.net/manual/en/ref.var.php
You need to have float
as datatype. This gets easily typecasted into int
. So, do this!
$Total = floatval($amount) * floatval($price);