Skip to main content
added 7 characters in body
Source Link
mickmackusa
  • 49.5k
  • 13
  • 99
  • 166

You can call number_format() on the lone returned value from your query if you want a formatted string with thousands placeholders otherwise use round() to return a float value.

public function getAveRating(int $restoid): float { return round( $this->db ->select_avg('rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'), 2 ); } 

Or you could round in the query itself.

public function getAveRating(int $restoid): float { return (float)$this->db ->select('ROUND(AVG(rate), 2) rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'); } 

You can call number_format() on the lone returned value from your query if you want a formatted string with thousands placeholders otherwise use round() to return a float value.

public function getAveRating(int $restoid): float { return round( $this->db ->select_avg('rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'), 2 ); } 

Or you could round in the query itself.

public function getAveRating(int $restoid): float { return $this->db ->select('ROUND(AVG(rate), 2) rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'); } 

You can call number_format() on the lone returned value from your query if you want a formatted string with thousands placeholders otherwise use round() to return a float value.

public function getAveRating(int $restoid): float { return round( $this->db ->select_avg('rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'), 2 ); } 

Or you could round in the query itself.

public function getAveRating(int $restoid): float { return (float)$this->db ->select('ROUND(AVG(rate), 2) rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'); } 
Source Link
mickmackusa
  • 49.5k
  • 13
  • 99
  • 166

You can call number_format() on the lone returned value from your query if you want a formatted string with thousands placeholders otherwise use round() to return a float value.

public function getAveRating(int $restoid): float { return round( $this->db ->select_avg('rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'), 2 ); } 

Or you could round in the query itself.

public function getAveRating(int $restoid): float { return $this->db ->select('ROUND(AVG(rate), 2) rate') ->get_where('ratings', ['restoid' => $restoid]) ->row('rate'); } 
Notice added Posted by Recognized Member/Admin in PHP mickmackusa