Jump to content

Get three decimal places


gple

Recommended Posts

$roster=mysql_query("select *, (hits/ab) as avg from softball_players, softball_rosters, softball_ostats where softball_ostats.roster_id=softball_rosters.id and softball_players.id=softball_rosters.player_id and softball_rosters.year='$year' order by avg desc");
$roster_num=mysql_numrows($roster);

 

How do I get avg to appear in three decimal places? Not two as this is outputting

Link to comment
Share on other sites

I did and I am still getting it to two decimal places. I think something has to be done in the query where I coded (HITS/AB) as AVG. I think there is more coding involved here to have AVG go to three decimal places.

Link to comment
Share on other sites

If there's only two decimal places being shown without you doing anything, then it would suggest that the number can be shown exactly to two decimals - that is, can be written as a fraction with 100 as the denominator.

 

Perhaps you wanted 3 decimals to be shown regardless? So an extra 0 would be shown? If so, you can use the number_format() function:

 

echo number_format($var,3);

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.