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
https://forums.phpfreaks.com/topic/101058-get-three-decimal-places/
Share on other sites

I don't totally understand what you mean, but i know you can format numbers with printf:

 

printf ("%01.3f", $MyNumber);

 

That should print to 3dp

 

Haven't actually used this before though, so someone please correct my if i am wrong

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);

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.