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