获取两个数字之间的百分比

问题描述 投票:0回答:1

所以我有一个投票网站,每个问题都有两个选项。比如说问题A有130个答案是YES,90个答案是NO,我怎么计算有多少百分比的人选择了YES的答案,又有多少人选择了NO的答案?

例如我试过多个方程式,但最后都会给出错误的信息。我一直在研究这个问题,但数学并不是我最擅长的科目。我真的很感谢你对我的帮助。谢谢!所以我有一个投票网站,每个人都有自己的想法。

php math equation algebra
1个回答
2
投票

这里是你如何可以做到这一点

<?php

$yes = 130;
$no = 90;

$total_votes = $yes+$no;

if($total_votes > 0){
    $yes_percentage = ($yes/$total_votes) *100;
    $no_percentage = ($no/$total_votes) *100
}
else{
    $yes_percentage = 0; 
    $no_percentage = 0;

}

0
投票

首先,你需要得到总人数。

$total = $yes + $no;

然后,如果你想要yes的百分比。

($yes / $total) * 100;

0
投票

YES的百分比

 Yes % = (total answers of yes / total ansers)*100
    $yes = 130;
    $no = 90;
    $totals = $yes+$no;
    $yes_per = ($yes/$totals) *100;

百分比为No

 No % = (total answers of No / total ansers)*100

    $no_per = ($no/$totals) *100

0
投票
TotalParticipants=130+90=220
YesVotedParticipants=130
NoVotedParticipants=90

YesVotedPaticipants percent(%)= (YesVotedParticipants/TotalParticipants)*100
                                 = (130/220)*100 =59.09 %

NoVotedPaticipants percent(%)= (NoVotedParticipants/TotalParticipants)*100
                                 = (90/220)*100 =40.90 %
© www.soinside.com 2019 - 2024. All rights reserved.