Jump to content

Check percentage intervals


MuseiKaze

Recommended Posts

Hiya, im having a bit of trouble finding a solution to a problem im having. I have a program ive written and it prints out a percentage everytime it checks an item, but I need to reduce the amount of times it prints to the page because its causing some lag due to the number of items.

 

Im using this to find the percentage completed

 

$getpercent = (100 / $total) * $i;

$percent = round($getpercent, 2);

 

Is there any way I can use a statement to find out if the percentage is at an interval of say 5. So it would only print out at 5%,10%,15% etc.. Hope that makes sense.

 

Thanks heaps

Link to comment
https://forums.phpfreaks.com/topic/193885-check-percentage-intervals/
Share on other sites

After a bit of messing around I found a solution that lets me check every 1% by rounding down the percent to 0 decimal places and storing $percent in $interval if percent isnt equal to interval. Seems to work fine. Would still be interested to know if theres a function or other method that can use to do this though.

 

$getpercent = (100 / $total) * $i;

$percent = round($getpercent, 0);

 

if ($percent != $interval)

{

$interval = $percent;

print "$percent%";

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.