[英]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'];
}
如何在獲得評分時將平均值限制為兩位小數?
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.