Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP数学问题_Php_Math_Format_Rounding - Fatal编程技术网

PHP数学问题

PHP数学问题,php,math,format,rounding,Php,Math,Format,Rounding,假设我将14/15除以100,得到93.33333的百分比,如何使用php将其显示为93.3% 这是代码 $percent = ($avg / 15) * 100; sprintf功能就是为此而设计的(另请参见): PHP有一个函数,可用于指定小数位数、小数分隔符使用的内容以及千位分隔符使用的内容: $percent = ($avg / 15) * 100; echo number_format($percent, 1) . '%'; // => 93.3% 根据您要查找的内容,rou

假设我将
14/15
除以100,得到
93.33333
的百分比,如何使用php将其显示为
93.3%

这是代码

$percent = ($avg / 15) * 100;

sprintf
功能就是为此而设计的(另请参见):

PHP有一个函数,可用于指定小数位数、小数分隔符使用的内容以及千位分隔符使用的内容:

$percent = ($avg / 15) * 100;
echo number_format($percent, 1) . '%'; // => 93.3%

根据您要查找的内容,round()也是一个不错的选择。
$percent = ($avg / 15) * 100;
echo number_format($percent, 1) . '%'; // => 93.3%