Jump to content

Help with my function


vegnadragon

Recommended Posts

ok here is my percentage function,

 

    function percent($num_amount, $num_total)

    {

$count1 = $num_amount / $num_total;

$count2 = $count1 * 100;

$count = number_format($count2, 0);

        return $count;

    }

What i want to do is get the percentage of my time left, i have a saved time in my database and compare with the actual time to get my percentage however it only gives me 100% something is off on my logic and i can't think about it.

Link to comment
https://forums.phpfreaks.com/topic/91471-help-with-my-function/
Share on other sites

Because your starting time was not zero on the Unix timestamp scale, you need to normalize the values by subtracting out the actual starting time -

 

<?php 
function percent($num_start,$num_amount, $num_total)
    {
   $count1 = ($num_amount-$num_start) / ($num_total-$num_start);
   $count2 = $count1 * 100;
   $count = number_format($count2, 0);
        return $count;
    }

$num_total =  1203220050;
$num_amount = 1203217774; // in this example, this is at the 50% point between the start and total times.
$num_start =  1203215498;
echo percent($num_start,$num_amount,$num_total);
?>

Link to comment
https://forums.phpfreaks.com/topic/91471-help-with-my-function/#findComment-468631
Share on other sites

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.