百分比计算在PHP
问题描述:
我想caluclate低于一定百分比(这由我需要被围捕,但它一直显示100我如何在PHP中使用下面的计算比例的方式是例如:百分比计算在PHP
$totalmarks += (int)$questionData['questionmarks'];
$studentmarks += (int)$questionData['studentmark'];
$percentage = $studentmarks/$studentmarks * 100;
echo $percentage;
答
你的公式是错误的,您是通过自身分裂studentmarks
它必须由totalmarks
划分目前它好像说$percentage = 1/1 * 100
;。这将总是导致100
$percentage = ($studentmarks/$totalmarks) * 100;
$percentage = round($percentage,2);
答
最简单的方法(恕我直言)是始终个鸿沟 totalmarks ,然后乘以它值你想要的(学生)的百分比
$percentage = ($totalmarks/100) * $studentmarks
答
围捕你需要使用小区()
echo ceil(($questionData['studentmark']/$questionData['questionmarks']) *100);
+1
你应该用你的公式中的studentmarks替换questionmarks – Buksy 2013-03-08 06:43:29
答
我希望这段代码可以帮助你:)
$totalmarks += (int)$questionData['questionmarks'];
$studentmarks += (int)$questionData['studentmark'];
$percentage = ($studentmarks/ $totalmarks) * 100;
echo $percentage;
Aorry bout th在错误的情况下,做了这个5点,最终在哈哈之后直接睡着了。对不起,但谢谢你的回答 – Manixman 2013-03-08 11:01:40