Price column - 2 decimals?

Hi,
i have a field in the db that is set to ‘float’ which holds a price, but when you enter say 444.50… it saves it as 444.5 and therefore displays on the page as 444.5.

Do i need to change the field type to something else? or can i just rewrite this below so it shows 2 decimals, if so how? :slight_smile:

<?php echo $row_jobs[‘price’]; ?>

thanks.


<?php echo number_format($row_jobs['price'],2); ?>

http://php.net/manual/en/function.number-format.php

that’s all it was, i feel so bad now :slight_smile:
thanks Kyle…

No problem, number_format is also a great tool to format numbers which are higher than 999… for example:


$price = 5000;
echo $price; // this shows 5000
echo number_format($price); // this shows 5,000 with the comma

just a word of caution, FLOAT is an approximate datatype

if your prices always need to be accurate to the penny, be aware that with FLOAT you run the risk of inaccuracy in calculations

use DECIMAL instead