这是我的代码!如何获得只有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位小数?
答案 0 :(得分:0)
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);
}
答案 1 :(得分:0)
将return $query['rate'];
更改为return round($query['rate'],2);