lakeshoretech Posted November 29, 2010 Share Posted November 29, 2010 $f15 = 0.345677 (output from sql data pull) <?php echo number_format ($f15,3); ?> output = 0.345 <?php echo ltrim($f15,"0"); number_format ($f15,3); ?> output = .345677 How do I combine these so that I am BOTH rounding the result AND trimming a leading zero? Seems I can get one or the other, but not both. Suggestions on the syntax? Quote Link to comment Share on other sites More sharing options...
s0c0 Posted November 29, 2010 Share Posted November 29, 2010 I am not sure why you would want to, but an inelegant solution would be to use the substr() function to remove the first character if the first character is equal to zero. Quote Link to comment Share on other sites More sharing options...
lakeshoretech Posted November 29, 2010 Author Share Posted November 29, 2010 s0c0 - ? Why I'd want to what? You lost me. Needing my result to be a "batting average" of sorts. Eliminate zero (but not a 1) before the decimal and round to 3 places. Quote Link to comment Share on other sites More sharing options...
laffin Posted November 29, 2010 Share Posted November 29, 2010 <?php echo ltrim(number_format ($f15,3),"0"); ; ?> Quote Link to comment Share on other sites More sharing options...
lakeshoretech Posted November 29, 2010 Author Share Posted November 29, 2010 Thanks. Perfect. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.