平均评分
这是我的代码!如何获得只有 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);