Jump to content

How do you round the result from an array?


sptrsn

Recommended Posts

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>" .

 

*****************************************************************

 

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 />';
}
?>

<?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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.