php - 如何以百分比显示数字
问题描述
我想知道我如何呈现百分比,这是代码
//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;
非常感谢所有帮助过的人
推荐阅读
- sql - SQL Server:在多个换行后提取字符串,直到字符串后换行
- c# - 如何在数组的列表中搜索字符串?
- api - 如何将视频 Youtube 放入我的 Angular 应用程序
- arrays - 打字稿中多维数组中的项目总和
- javascript - 侦听所有消息并可以编辑消息的松弛应用程序所需的最小权限是多少
- r - 如何应用过滤器
- joomla - Baqend Speed Kit Plesk - Joomla 网站几乎没有加速
- firefox - 书签在一个页面上有效,但在另一个页面上无效
- excel - 从模块而不是功能区执行时,代码运行速度要快得多
- javascript - 我可以知道 Firefox 跟踪保护何时在 javascript 代码中打开吗?