title: pushing and evaluating Stack <double>
body: <p>First time posting so please inform me of how to improve.</p>
  
  <p>I'm working on a program to convert infix notation to postfix and then evaluate.  My conversion to postfix went well, but I'm having some trouble with my evaluation.  In the code below, when I try to convert the operands into a double variable 'number' they don't maintain their value (see runtime output below).  Here is part of the method in question (the print statements are for debugging only).</p>
  
  <pre><code>public boolean evaluatePostfix(StringBuffer postfix)
      {
          Stack &lt;Double&gt; operand = new Stack &lt;Double&gt;();//stack to hold operand values
          double answer = 0; //variable to hold result of expression
          boolean error = false; //tests for input error
          int pos = 0; //temp veraible stores position in postfix expression
          double number = 0; //temp variable to convert char to double. also stores that value for reference
          double val1 = 0; //first value for operations
          double val2 = 0; //second value for operations
          double val3 = 0; //answer for val1 and val2
  
          while (!error &amp;&amp; pos &lt; postfix.length())
                  {
                      System.out.println(postfix.charAt(pos));
                      if (postfix.charAt(pos) == ' ')
                          ; //do nothing
                      else if (Character.isDigit(postfix.charAt(pos)))
                      {
                          number = Double.parseDouble(postfix.substring(pos));
                          System.out.printf ("number = %f", number);
                          operand.push(number);
                      }
                      else
                      {
                          val1 = operand.pop();
                          val2 = operand.pop();
                          System.out.printf ("val1: %f\tval2: %f\n", val1, val2);
  </code></pre>
  
  <blockquote>
    <p>---At runtime--- 1</p>
    
    <p>number = 49.000000</p>
    
    <p>8</p>
    
    <p>number = 56.000000</p>
    
    <p>+</p>
    
    <p>val1: 56.000000</p>
    
    <p>val2: 49.000000</p>
    
    <p>val3 = 105.000000</p>
    
    <p>105.0</p>
  </blockquote>