首页 > 解决方案 > 如何以百分比显示数字

问题描述

我想知道我如何呈现百分比,这是代码

//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;

标签: phpmathpercentage

解决方案


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

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

非常感谢所有帮助过的人


推荐阅读