或者显示平均值我有这个:
$item = mysql_query("SELECT AVG(top) AS total FROM " . "$config_ccms_prefix" . "news where id='$id'");
while ($cms = mysql_fetch_assoc($item)) {
$avg = ceil(($cms[total]),0.5);
}
//......
例子:
如果$ccms[total]=3.4到3.5,或7.8到8,或9.3到9.5,但不是9.5到10,或4.5到5,我需要四舍五入。实际上,我不确定这是可能的。
平均值不适合我!!
最佳答案
你需要这样做:
$avg = ceil($cms['total']*2)/2; //result of
结果将是:
1.5 = ceil(1.1*2)/2; //CEIL(2.2) = 3.0 / 2 = 1.5;
1.5 = ceil(1.2*2)/2; //CEIL(2.4) = 3.0 / 2 = 1.5;
1.5 = ceil(1.3*2)/2; //CEIL(2.6) = 3.0 / 2 = 1.5;
1.5 = ceil(1.4*2)/2; //CEIL(2.8) = 3.0 / 2 = 1.5;
1.5 = ceil(1.5*2)/2; //CEIL(3.0) = 3.0 / 2 = 1.5;
2 = ceil(1.6*2)/2; //CEIL(3.2) = 4.0 / 2 = 2;
2 = ceil(1.7*2)/2; //CEIL(3.4) = 4.0 / 2 = 2;
2 = ceil(1.8*2)/2; //CEIL(3.6) = 4.0 / 2 = 2;
2 = ceil(1.9*2)/2; //CEIL(3.8) = 4.0 / 2 = 2;
2 = ceil(2*2)/2; //CEIL(4) = 4.0 / 2 = 2;
干杯
关于php - php汇总/ceil合并mysql AVG(),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8681576/