Jump to content

Simple question... maybe?


timmy0320

Recommended Posts

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!  :P 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

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.