jester626 Posted September 19, 2007 Share Posted September 19, 2007 This is probably pretty simple but I can't seem to find the exact answer I am looking for. I am pulling a couple of numbers from a database (productcost and productprice). I am trying to subtract the cost from the price to calculate the profit of the item. I have this part working with no problem. My problem lies when the final number has a trailing zero it will drop that number (i.e. 1.2 as opposed to 1.20) Here is what I am using: $profit = $row_viewcoils['ProductPrice'] - $row_viewcoils['ProductCost']; echo $profit; Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/69925-add-trailing-zero-to-calculation/ Share on other sites More sharing options...
redarrow Posted September 19, 2007 Share Posted September 19, 2007 number_format() function you need. Quote Link to comment https://forums.phpfreaks.com/topic/69925-add-trailing-zero-to-calculation/#findComment-351193 Share on other sites More sharing options...
pikemsu28 Posted September 19, 2007 Share Posted September 19, 2007 echo number_format($profit, 2); Quote Link to comment https://forums.phpfreaks.com/topic/69925-add-trailing-zero-to-calculation/#findComment-351196 Share on other sites More sharing options...
jester626 Posted September 19, 2007 Author Share Posted September 19, 2007 That did the trick, thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/69925-add-trailing-zero-to-calculation/#findComment-351202 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.