dongwei2030 2016-04-30 16:48
浏览 65
已采纳

如何在PHP中将(KD)数字转换为胜利百分比

I need to calculate a win loss ratio from my app in PHP (Laravel 5.2)

I have these two numbers:

$array['WinLoss'] = $array['GamesWon'] / $array['TotalGamesLost'];

Which gives me:

Win: 480

Loss: 400

I tried doing this in my view:

{{ round((float)$WinLoss * 100) . '%' }}

but it gives me 120%. Thats obviously not correct, it should be around 58%

How would I calculate to show around 58% not 120%?

  • 写回答

1条回答 默认 最新

  • dongyun7897 2016-04-30 16:49
    关注
     $array['WinLoss'] = round(100 * ($array['GamesWon'] / ($array['TotalGamesLost'] + $array['GamesWon'])), 2);
    

    would give you % of games won

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?