该sprintf功能是为此而作出的(另见手册):
echo sprintf('%.1f%%', $percent);
Run Code Online (Sandbox Code Playgroud)
PHP有一个number_format函数,它允许您指定小数位数,小数点分隔符的用途以及千位分隔符的用途:
$percent = ($avg / 15) * 100;
echo number_format($percent, 1) . '%'; // => 93.3%
Run Code Online (Sandbox Code Playgroud)