I am using Laravel on developing my new app. I have initiated average function on a rating column in my database table and now I am just curious how could I make the average value from “3.3333” into “3.3”.
$rating = Rating::avg('value'); echo $rating;
Advertisement
Answer
You can use php’s inbuilt functions for rounding. In this case, you want a precision of one, so round($rating, 1)
. For more info, please see the docs: http://php.net/round