billhobbs Posted September 26, 2010 Share Posted September 26, 2010 <?php $totalcreditstd = $row_rsCreditPurchaseMoney['SUM(quantity)']; $totalcreditsdollar = $totalcreditstd * $Mutliplier; echo $totalcreditsdollar; ?> I'm using the above calculation to display a total amount. Problem is that if the calculation total is 7.5 I want it to show up as 7.50 I want to force the second number. How can I do that? Thanks. Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/ Share on other sites More sharing options...
Alex Posted September 26, 2010 Share Posted September 26, 2010 echo number_format(7.5, 2); // 7.50 number_format Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/#findComment-1115915 Share on other sites More sharing options...
Pikachu2000 Posted September 26, 2010 Share Posted September 26, 2010 Or possibly: money_format() Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/#findComment-1115916 Share on other sites More sharing options...
billhobbs Posted September 26, 2010 Author Share Posted September 26, 2010 Perfect, thanks. Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/#findComment-1115978 Share on other sites More sharing options...
The Little Guy Posted September 26, 2010 Share Posted September 26, 2010 or... echo round($number, 2); Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/#findComment-1115981 Share on other sites More sharing options...
roopurt18 Posted September 26, 2010 Share Posted September 26, 2010 If you're doing money / financial calculations make sure you're using BC or GMP math functions. Do not use floats. Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/#findComment-1116032 Share on other sites More sharing options...
Alex Posted September 26, 2010 Share Posted September 26, 2010 or... echo round($number, 2); round(7.5, 2); will output 7.5 Link to comment https://forums.phpfreaks.com/topic/214445-force-to-2-decimal-points/#findComment-1116038 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.