Php 如何以百分比显示数字

Php 如何以百分比显示数字,php,math,percentage,Php,Math,Percentage,我想知道我是如何给出一个百分比的,下面是代码 //The number taken from the database $minos = $ud['bnk']['gold']; The number that is supposed to be in percent through the database (the database has a number and not a percentage for example 2) $plus= $ud['bnk']['ent_level']

我想知道我是如何给出一个百分比的,下面是代码

//The number taken from the database
$minos = $ud['bnk']['gold'];

The number that is supposed to be in percent through the database (the database has a number and not a percentage for example 2)
$plus=  $ud['bnk']['ent_level'];

And here is a simple calculation of X + 2% = Y
$sava = $minos + $plus; 
根据一份网络指南,我尝试过这样做,但对我来说不起作用,我希望这个数字是一个百分比,但不成功

function get_percentage($total, $number)
{
  if ( $total > 0 ) {
   return round($number / ($total / 100),$ud['bnk']['ent_level']);
  } else {
    return 0;
  }
}

$minos = $ud['bnk']['gold'];
$plus =  get_percentage(100,$ud['bnk']['ent_level']).'%';
$sava = $minos + $plus;


我用你给我的解了这个方程,非常感谢,方法是:

$minos = $ud['bnk']['gold'];
$plus =  ($minos / 100) * $ud['bnk']['ent_level'];
$sava = $plus;

非常感谢所有帮助过你的人

$percent=$number÷$total*100你好,Daan,我不知道该放在哪里,我试着玩你给我的东西,我不清楚。你会把它放在与你现有的百分比计算公式相同的位置,以替换它。要了解原因,请仔细观察Daan写的内容,并将您与您的进行比较。特别是,与您的符号相比,仔细查看介于
$total
100
之间的符号。老实说,你可以在网上数千个地方找到计算百分比的公式。这是基础数学。问题不在于PHP代码本身,而在于您使用了错误的数学。