Problem with Function Arguments

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jenkinsloveschicken
    New Member
    • Dec 2006
    • 56

    Problem with Function Arguments

    I imagine this is a n00b mistake, but the problem I am having is that the first function(stratQ ual) is evaluating to "No" despite the argument being passed to it being greater than 80.00. The second function evalutes correctly. I have tried re-writing the first function as a switch case, but with the same results. I have also tried setting $stratQual = $faPercToGoal within the function and the function returns and displays the correct value for $faPercToGoal.

    The syntax for the two appears identical, so I can't understand why they are not evaluating in the same manner. Can someone please shed some light on what I am doing wrong here?

    Here is how I process each argument prior to sending to the function:
    [code=php]
    $faPercToGoal = number_format(( ($maxValFin/$faSValFin) * 100), 2);
    $stratQual = stratQual($faPe rcToGoal);

    $qamPercGoal = number_format(( ($qamActTot/$qamGoalSum)*10 0), 2);
    $qamQual = qamQual($qamPer cGoal);


    //Determine if agent strategic value percent/goal meets requirements
    function stratQual($faPe rcToGoal)
    {
    if ($faPercToGoal >= '80.00')
    {
    $stratQual = "Yes";
    }
    else
    {
    $stratQual = "No";
    }
    return $stratQual;
    }


    //Determine if agent quality percent/goal meets requirements
    function qamQual($qamPer cGoal)
    {
    if ($qamPercGoal >= '95.00')
    {
    $qamQual = "Yes";
    }
    else
    {
    $qamQual = "No";
    }
    return $qamQual;
    }
    [/code]
    Last edited by ak1dnar; Oct 27 '07, 05:42 PM. Reason: Added code tags
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    There is no issue with the functions. problem is with the calling parameters of the function. since you have used number_format() it will Format the number with grouped thousands.
    Say you are passing like this :

    [CODE=php]
    $qamPercGoal = number_format(( 50*100), 2);
    echo $qamQual = qamQual($qamPer cGoal); [/CODE]

    So the calling parameter now it's 5,000. So function is not evaluating correclty. You have to pass 5000 instead.

    So remove those number_format from the calling parameters.

    EDIT: I think so far you have used number which lesser than 1000 so number_format function sends the number as it is, in other words with out grouping to thosands.
    Ex: number_format(( 5*100), 2); // 500

    Comment

    • jenkinsloveschicken
      New Member
      • Dec 2006
      • 56

      #3
      Worked like a charm! Thank you so much. I had a feeling it had to do with the $faPercToGoal value as it is frequently greater than 1,000.

      Is there a different function I could use instead of number_format? I was trying to format the value for display in-page as well as send it to the appropriate function without creating two variables.

      Again, thank you so much for the help!

      -Jenkins

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Originally posted by jenkinsloveschi cken
        Worked like a charm! Thank you so much. I had a feeling it had to do with the $faPercToGoal value as it is frequently greater than 1,000.

        Again, thank you so much for the help!

        -Jenkins
        You are welcome. !

        Is there a different function I could use instead of number_format? I was trying to format the value for display in-page as well as send it to the appropriate function without creating two variables.
        I'm Sorry no idea about another function, that suits for both Formatting and Calculations. But by using Formatted Number you can't go for a calculation.

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, Jenkins.

          Why not just call stratQual() before you use number_format() and compare directly against the float value?

          Comment

          Working...