简体   繁体   中英

Calculate the percentage of a number in PHP laravel

I need to print a discount amount from the discount percentage. For example, if I put manually these values .i can print 150 as the discount amount. if I assign the variables it will be shown 0

Manual 
$ActualPrices=400
$percentToGet=37.50%
$percentInDecimal = $percentToGet / 100;
$percentamnt= $percentInDecimal * $ActualPrices;

Assigning to Variables

$perc=0;
$ActualPrices=$value->ActualPrice;
$percentToGet = $perc;
$percentInDecimal = $percentToGet / 100;
$percentamnt= $percentInDecimal * $ActualPrices;
$data['data']['products'][]=[
'percentamnt'=>$percentamnt,
 ];
      }

Try to use this code block where the average can be calculated, it is a solution option

$item=200;
$numeroVotos=5000;
$percent = round($item/$numeroVotos*100);
if ($percent<=100){ 
    echo $percent;
}
else {
    echo "100"; 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM