ejaboneta Posted April 6, 2010 Share Posted April 6, 2010 I know this is probably really simple but I'm trying to round() dollar amounts. When the value is rounded to 10.50, it comes out to 10.5 without the last 0. How can I make sure round() leaves the zero at the end? Quote Link to comment https://forums.phpfreaks.com/topic/197799-rounding-to-2-decimal-places/ Share on other sites More sharing options...
mattal999 Posted April 6, 2010 Share Posted April 6, 2010 number_format(round(10.52122, 2), 2); Quote Link to comment https://forums.phpfreaks.com/topic/197799-rounding-to-2-decimal-places/#findComment-1037992 Share on other sites More sharing options...
Chris92 Posted April 6, 2010 Share Posted April 6, 2010 Try this, I haven't tested it. $round = round( 10.51, 2 ); $array = explode(".", $round); if( strlen($array[1]) != "2" ) { $round .= "0"; } Quote Link to comment https://forums.phpfreaks.com/topic/197799-rounding-to-2-decimal-places/#findComment-1037993 Share on other sites More sharing options...
jcbones Posted April 6, 2010 Share Posted April 6, 2010 This may help you out. http://php.net/manual/en/function.money-format.php Quote Link to comment https://forums.phpfreaks.com/topic/197799-rounding-to-2-decimal-places/#findComment-1038030 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.