title: Javascript prevent NaN while dividing
body: <p>I have been working on a PI calculation program using javascript.  </p>
  
  <pre><code>     circumference
  Pi = -------------
         diameter
  </code></pre>
  
  <p>When <code>r = the radius</code>, the circumference = 2πr, and the diameter = 2r. </p>
  
  <p>This is what I have tried to do:</p>
  
  <pre><code>    var pi = Math.Pi,
      var r = 2
      ans = (2 * pi * r) / (2 * r);
      alert(ans);
  </code></pre>
  
  <p>Seems like it should work, right? But instead I get an alert message that says, "<strong>NaN</strong>."</p>
  
  <p>Is there any way I can make a function like this:</p>
  
  <pre><code>function divide(numerator, denominator, decimal_places){
      //code
  }
  //and then:
  divide(2πr, 2r, 30);//that would calculate Pi to 30 decimal places.
  </code></pre>
  
  <p>Does anyone know how I could make such a function using javascript? Thank you so much.</p>