dswqz24846
dswqz24846
2018-11-10 20:57

如何计算出有多少人支付的百分比

已采纳

I have been trying to google this for hours but am finding it hard to find the maths to achieve this.

If the total payment is 200 GBP and the user has paid 100 GBP - he has paid 50% of the total.

I am trying to translate this to an algorithm but cannot get the expected result.

I have tried:

($total / $paid) * 100;
(($total + $paid) / 100) * 2;
($total - $paid) / 100;

But neither of this is giving me 50% when I use 200 as the total payment and 100 as the amount paid. Any help would be appreciated. I'm not very good at maths.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douyeyan0650 douyeyan0650 3年前

    Simply do:

    $percent = 100 * $paid/$total;
    

    To get the percent value up to two decimal places only, you can use the Round() function:

    $percent = ROUND(100 * $paid/$total, 2);
    
    点赞 评论 复制链接分享
  • doushi6932 doushi6932 3年前

    It is very simple just do this $percentPaid = $paid/$total * 100;

    点赞 评论 复制链接分享

相关推荐