Lets say I divide 14 / 15
times it by 100 to get the percentage which is 93.33333333333333
how can I display it as 93.3%
using php?
Here is the code.
$percent = ($avg / 15) * 100;
Lets say I divide 14 / 15
times it by 100 to get the percentage which is 93.33333333333333
how can I display it as 93.3%
using php?
Here is the code.
$percent = ($avg / 15) * 100;
The sprintf
function is made for this (see also the manual):
echo sprintf('%.1f%%', $percent);
PHP has a number_format
function which lets you specify the number of decimals, what to use for the decimal separator, and what to use for the thousands separator:
$percent = ($avg / 15) * 100;
echo number_format($percent, 1) . '%'; // => 93.3%