sptrsn Posted August 1, 2009 Share Posted August 1, 2009 Thanks for any help. I'm not a programmer, but have pieced together a bit of code to allow us to look up basic data on our mobile phones. I need to round the number in one of the fields to zero decimals. The data coming out of the 'amount' field has 4 decimal places, and all I need is a whole number. I've been reading all over the place and have tried several different techniques, but just can't quite get it. Sure appreciate your help. Thanks, Steve Here's my code.... **************************************************************** $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name: {$row['last_name']}, {$row['first_name']}<br>" . "Company: {$row['company']}<br>" . "Amount: {$row['amount']}<br>" . ***************************************************************** Link to comment https://forums.phpfreaks.com/topic/168373-how-do-you-round-the-result-from-an-array/ Share on other sites More sharing options...
ignace Posted August 1, 2009 Share Posted August 1, 2009 http://be2.php.net/number_format Link to comment https://forums.phpfreaks.com/topic/168373-how-do-you-round-the-result-from-an-array/#findComment-888179 Share on other sites More sharing options...
sptrsn Posted August 1, 2009 Author Share Posted August 1, 2009 Thanks. I've read that page 5 times and ....well.....I'm stupid. I think this is what I want........ number_format(2, ',', '.'); But where do I insert it, or how do I combine these statements? "Amount:{$row['amount']}<br>" . Link to comment https://forums.phpfreaks.com/topic/168373-how-do-you-round-the-result-from-an-array/#findComment-888194 Share on other sites More sharing options...
bundyxc Posted August 1, 2009 Share Posted August 1, 2009 Just a few syntax mistakes. Fixed: <?php $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo 'Name: ' . $row['last_name'] . ', ' . $row['first_name'] . '<br />'; echo 'Company: ' . $row['company'] . '<br />'; echo 'Amount: ' . $row['amount'] . '<br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/168373-how-do-you-round-the-result-from-an-array/#findComment-888213 Share on other sites More sharing options...
ignace Posted August 1, 2009 Share Posted August 1, 2009 <?php $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo 'Name: ' . $row['last_name'] . ', ' . $row['first_name'] . '<br />'; echo 'Company: ' . $row['company'] . '<br />'; echo 'Amount: ' . number_format($row['amount'], 2, ',', '.') . '<br />'; } ?> I'm stupid No you are not. Rome wasn't build in 1 day, all it takes is effort and some common sense. Link to comment https://forums.phpfreaks.com/topic/168373-how-do-you-round-the-result-from-an-array/#findComment-888342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.