3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(74.6779,25.918,44.9589); $total = array_sum($arr); $total_percentage = 0; ini_set('precision',100); foreach($arr as $total_item) { $percentage = ($total_item*100)/$total; var_dump($percentage); $percentage = round($percentage,2); // without this works, but result large numbers.. e.g: "51.305693800548" echo $percentage; echo "\n"; $total_percentage = round($total_percentage+$percentage,2); } echo round($total_percentage,1);

preferences:
45.48 ms | 402 KiB | 5 Q