Page 1 of 1

Help with formatting numbers

Posted: Tue Aug 05, 2003 12:39 am
by leozayas
guys and ladies,

I have a softball website that I run, it is all run by php and MySQL database.

The problem I am having is this: I keep complete stats on every player, when I want to display the stats that are percentile such as batting average, I would like them to display as .667 or whatever the case may be. My problem is that I use the printf("%.3f", $variable) function, however this gives me 0.667, I would like to get the leading zero off of there and have a number only appear in front of the decimal when it is 1.000.

Is there a function that I am missing? or is there a way to do this that I have not come accross yet?

Any and all help will be fully appreciated, by the way an example of what I am talking about can be found at http://24.126.233.101/masterstats.php?tournyid=62203

Thank you

Leo Zayas

Posted: Tue Aug 05, 2003 1:10 am
by Tubbietoeter
you coul use preg_replace(), see http://www.php.net for details on that function