PDA

View Full Version : truncating the database avarage to 2 decimals


woofy
06-05-2011, 05:04 PM
I have a php line that displays the average of a rating system (5 star), I currently have it rounding off to 2 decimals. So if the average is 3.333333 it would round it to 3.32, the problem I am encountering is when I get a value such as 4.50000 it rounds it to 4.5, without the zero. I want to display the extra zero in these cases so it would read 4.50 , basically I want all my values to display 3 characters in length. The current command I use is

<?php echo round($row_rsRATE['Avg(rating)'], 2); ?>

How can i modify this line to achieve the desired results?

davidj
06-06-2011, 01:18 PM
Try this

<?php echo number_format(round($row_rsRATE['Avg(rating)']),2); ?>