Reputation: 232
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.
Upvotes: 0
Views: 1130
Reputation: 1070
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
Upvotes: 2
Reputation: 167182
You need to have float
as datatype. This gets easily typecasted into int
. So, do this!
$Total = floatval($amount) * floatval($price);
Upvotes: 2