phpretard Posted November 14, 2009 Share Posted November 14, 2009 How I get ".00" to show if there is nothing after the decimal in the Database. For example if I insert 2.00 [decimal (10,2)] in the database the php will only display the ".00" if there is a value after the decimal. The code works fine it's the .00 that's got me. function getBalance(){ connect(); $balanceQ=mysql_query("select cart.eventID, cart.userID, competitions.id, competitions.price, competitions.coachcost FROM cart LEFT JOIN competitions ON competitions.id = cart.eventID where cart.userID='123' ") or die(mysql_error()); while($balance=mysql_fetch_assoc($balanceQ)) { $total +=$balance['price'] + $balance['coachcost']; } // get previous payments $historyQ=mysql_query("select * from account where userID='123' "); while($history=mysql_fetch_assoc($historyQ)) { $subtract +=$history['amount']; } free($balanceQ); free($historyQ); echo "$".($total - $subtract); //<<<< PROBLEM } Any help? Link to comment https://forums.phpfreaks.com/topic/181480-solved-decimal-display/ Share on other sites More sharing options...
phpretard Posted November 14, 2009 Author Share Posted November 14, 2009 echo "$".number_format($total - $subtract, 2); Link to comment https://forums.phpfreaks.com/topic/181480-solved-decimal-display/#findComment-957339 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.