timmy0320 Posted February 25, 2008 Share Posted February 25, 2008 Alright, I'm creating a "goal" calculator for Affiliates on my site. The situation is customers referred pay $100/mo for the service. I set a variable right now for the referred amount of customers (will later grab from database). I set this value to 3. The person enters their "goal amount per month" in dollars. I formatted it already to where if the percent value is > 100 then it stays at 100%. What I am having trouble doing. Let's say for instance, the customer inputs $301, it will return 3.01 customers. Is there a way if it's over >= .01 on the customer count then round up to the next number. I'm sure it's simple but honestly I've been out of high school since 03 and my brain is farting! Here's the code. if (isset($_POST['submit'])) { $referred = 3; // round the number entered $num = $_POST['goal']; $num = intval($num + .5); // figure out the amount of customers per month // each customer pays $100/mo and then round it $cust = $num / 100; //$cust = intval($cust + .5); // if the value is lower than $50, automatically one customer if ($num < 50 && $num != 0 ) { $cust = "1"; } $percent = ($referred / $cust) * 100; $percent = number_format($percent,1); if ($percent >= 100) { $percent = "100"; } //math echo "To get $".$num." a month, you will need to refer ".$cust." customer(s) to reach your goal. You are ".$percent."% there!"; } Link to comment https://forums.phpfreaks.com/topic/92936-simple-question-maybe/ Share on other sites More sharing options...
AndyB Posted February 25, 2008 Share Posted February 25, 2008 ceil() gets you close: http://us2.php.net/manual/en/function.ceil.php Link to comment https://forums.phpfreaks.com/topic/92936-simple-question-maybe/#findComment-476120 Share on other sites More sharing options...
timmy0320 Posted February 25, 2008 Author Share Posted February 25, 2008 ceil() gets you close: http://us2.php.net/manual/en/function.ceil.php Perfect! Much appreciated. Link to comment https://forums.phpfreaks.com/topic/92936-simple-question-maybe/#findComment-476130 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.