如何在获得评级时将平均值限制在小数点后 2 位


how do I limit the average into 2 decimal places in getting the rating?

平均评分

这是我的代码!如何获得只有 2 位小数的平均值?

 public function getAveRating($restoid){ 
      $where=array(
           "restoid"=>$restoid
           );
      $this->db->where($where);
      $this->db->select_avg('rate');
      $query = $this->db->get('ratings')->first_row('array');
      return $query['rate'];
 }

如何在获得评级时将平均值限制为小数点后 2 位?

http://php.net/round

 public function getAveRating($restoid){ 
      $where=array(
           "restoid"=>$restoid
           );
      $this->db->where($where);
      $this->db->select_avg('rate');
      $query = $this->db->get('ratings')->first_row('array');
      return round($query['rate'], 2);
 }

return $query['rate'];更改为return round($query['rate'],2);