PHP MySQL Average

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

PHP MySQL Average

Postby Kenneth » Fri Aug 09, 2002 11:59 am

Hi:

My name is Ken Cooper. I haev a question on Average. Well, I select data from a database, and I finally do something like
$avg = $count2/$count3

And my question is, well, the result of the $avg is usually something like:
23.59869368. What I mean is, it comes out to be a REALLY big number with lots of digits. Is there a way I can LIMIT the number so it only has 2 digits after the decimal point? Thanks alot, I really appreciate it!

Ken Cooper

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Fri Aug 09, 2002 12:04 pm

Again, just for help, if you need assistance on what I'm talking about, go to my site. http://www.coopercentral.org/poll/pollarchive.php - Then go to the bottom of the table and on the bottom right, it says Average, and thats a big number with lots of digits, I only was 2 digits after the decimal. Thanks.

Ken Cooper

User avatar
MadMed
New php-forum User
New php-forum User
Posts: 6
Joined: Thu Aug 08, 2002 3:41 pm
Location: Dallas, TX
Contact:

Postby MadMed » Fri Aug 09, 2002 1:15 pm

Ken,
Here is what you use: printf("%.2f",$avg);

Good Luck,
MadMed
[url]DotNetOS.com[/url]

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Fri Aug 09, 2002 1:33 pm

Thanks a lot, I really appreciate it. I shall try that. Thanks again!!!!

Ken Cooper

Jay

Postby Jay » Fri Aug 09, 2002 2:54 pm

Or you could try the more user friendly number_format() function? So you'll have number_format($avg,2);

Kenneth
New php-forum User
New php-forum User
Posts: 40
Joined: Fri Aug 09, 2002 11:53 am
Location: Rochester, NY
Contact:

Postby Kenneth » Fri Aug 09, 2002 3:09 pm

Thanks, that works too. Thanks a lot!!!

Ken Cooper


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron