Help with formatting numbers

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
leozayas
Forum Newbie
Posts: 1
Joined: Tue Aug 05, 2003 12:39 am

Help with formatting numbers

Post 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
Tubbietoeter
Forum Contributor
Posts: 149
Joined: Fri Mar 14, 2003 2:41 am
Location: Germany

Post by Tubbietoeter »

you coul use preg_replace(), see http://www.php.net for details on that function
Post Reply