Announcement

Collapse
No announcement yet.

Can pow be called by a user function?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Can pow be called by a user function?

    I get Reference error: POW not defined
    when I run this:

    PHP Code:

    // rnd function - round to two places
    function rnd(value) { // Round the price to iDecimals digits

    value =  value pow(10iDecimals);

        return 
    Math.round(valueiDecimals) / pow(10iDecimals);

    I looked pow up in the knowledgebase:

    pow(base, exponent) returns base to the power of exponent

    So what am I doing wrong/not doing right?

    Thanks in Advance.


    P.S. these decimals are driving me crazy!

  • #2
    buzzhorton
    pow is a method of the Math Object. The correct syntax is Math.pow()
    Alex

    Comment


    • #3
      Thanks.

      I guess you figured that I could figure it out...

      PHP Code:
      // rnd function - round to two places
      function rnd(valueiDecimals ) { // Round the price to iDecimals digits

      value =  value Math.pow(10iDecimals);

          return 
      Math.round(valueiDecimals) / Math.pow(10iDecimals);

      But I have a question.

      I had to pass iDecimals as a parameter.

      Is that because a function can only "see" what is passed to it?

      Thanks again

      Comment


      • #4
        buzzhorton

        Originally posted by buzzhorton
        Is that because a function can only "see" what is passed to it?
        It can only see what is passed to it or an external variable (see enclosed script for an example of the latter)
        Alex

        PHP Code:
        var 2;
        function 
        main(){
            var 
        calc();
            
        debugPrintln(y);//returns 4
        }
        function 
        calc(){
            var 
        Math.pow(2,x);
            return 
        z;

        Comment

        Working...
        X