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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.