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? Link to comment https://forums.phpfreaks.com/topic/220147-ltrim-rounding-how-to-combine-syntax/ 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. Link to comment https://forums.phpfreaks.com/topic/220147-ltrim-rounding-how-to-combine-syntax/#findComment-1140959 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. Link to comment https://forums.phpfreaks.com/topic/220147-ltrim-rounding-how-to-combine-syntax/#findComment-1140964 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"); ; ?> Link to comment https://forums.phpfreaks.com/topic/220147-ltrim-rounding-how-to-combine-syntax/#findComment-1140965 Share on other sites More sharing options...
lakeshoretech Posted November 29, 2010 Author Share Posted November 29, 2010 Thanks. Perfect. Link to comment https://forums.phpfreaks.com/topic/220147-ltrim-rounding-how-to-combine-syntax/#findComment-1140972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.