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. Link to comment https://forums.phpfreaks.com/topic/91471-help-with-my-function/ 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. Link to comment https://forums.phpfreaks.com/topic/91471-help-with-my-function/#findComment-468587 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 Link to comment https://forums.phpfreaks.com/topic/91471-help-with-my-function/#findComment-468589 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. Link to comment https://forums.phpfreaks.com/topic/91471-help-with-my-function/#findComment-468628 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); ?> Link to comment https://forums.phpfreaks.com/topic/91471-help-with-my-function/#findComment-468631 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.