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

 

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

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.