Search code examples
phpintdecimalmultiplication

php multiplying int by decimal produces an int?


So I'm trying to understand this behaviour: In my database table, I have a row quantity (int 11) and a column price (decimal 5,2). Multiplying them to get a total, outputs an integer... how's this possible?

$qty = 2;
$price = 10;
$total = $qty * $price;

echo "$total";

// Outputs 20. Shouldn't it output 20,00?


Solution

  • So, for anyone else wondering, there's a php currency formatting function. http://php.net/manual/it/function.money-format.php Check the manual for further informations, thanks for the ones that answered.