vegnadragon Posted February 17, 2008 Share Posted February 17, 2008 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 17, 2008 Share Posted February 17, 2008 Give an example of the numbers you are putting into the function call. Quote Link to comment Share on other sites More sharing options...
vegnadragon Posted February 17, 2008 Author Share Posted February 17, 2008 It is unix time measure, if i am correct. This is my saved time 1203220050 and this is the actual time 1203217774 Quote Link to comment Share on other sites More sharing options...
vegnadragon Posted February 17, 2008 Author Share Posted February 17, 2008 I guess it won't work for time, so i'll try to make one. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 17, 2008 Share Posted February 17, 2008 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); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.