gerkintrigg Posted August 4, 2006 Share Posted August 4, 2006 Hi. this is probably a very simple question, with a very simple answer, but it's baffling me...Does anyone here know how to echo a MySQL float variable as two decimal places? Currently I'm using it to store prices in a database and whenever a cost if like £1.50p it only displays £1.5 which simply looks wrong.Can anyone help please?Thanks. Link to comment https://forums.phpfreaks.com/topic/16538-mysql-float-variables-2-decimal-places/ Share on other sites More sharing options...
onlyican Posted August 4, 2006 Share Posted August 4, 2006 I know the round function worksround(5.2545, 2) would be 5.25round(1.5,2) should in theory be 1.50 Link to comment https://forums.phpfreaks.com/topic/16538-mysql-float-variables-2-decimal-places/#findComment-69149 Share on other sites More sharing options...
onlyican Posted August 4, 2006 Share Posted August 4, 2006 Also check out the number format and the money format functionshttp://es2.php.net/manual/en/function.number-format.phphttp://es2.php.net/manual/en/function.money-format.php Link to comment https://forums.phpfreaks.com/topic/16538-mysql-float-variables-2-decimal-places/#findComment-69150 Share on other sites More sharing options...
gerkintrigg Posted August 4, 2006 Author Share Posted August 4, 2006 Eventually i used:printf("%.2f", $total);Thanks everyone. Link to comment https://forums.phpfreaks.com/topic/16538-mysql-float-variables-2-decimal-places/#findComment-69211 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.