private BigDecimal evaluate(){
  if (m_display == null || m_display.equals("") || m_display.equals("0")) {
    m_number=new BigDecimal(0.0);
    return m_number;
  }
  StringTokenizer st=new StringTokenizer(m_display,OPERANDS,true);
  String token=st.nextToken();
  if (token.equals("-")) {
    if (st.hasMoreTokens())     token+=st.nextToken();
 else {
      m_number=new BigDecimal(0.0);
      return m_number;
    }
  }
  Number firstNumber;
  try {
    firstNumber=m_format.parse(token);
  }
 catch (  ParseException pe1) {
    log.log(Level.SEVERE,"Calculator.evaluate - token: " + token,pe1);
    m_number=new BigDecimal(0.0);
    return m_number;
  }
  BigDecimal firstNo=new BigDecimal(firstNumber.toString());
  m_number=firstNo;
  if (!st.hasMoreTokens())   return m_number;
  token=st.nextToken();
  if (OPERANDS.indexOf(token) == -1) {
    log.log(Level.SEVERE,"Calculator.evaluate - Unknown token: " + token);
    return m_number;
  }
  char op=token.charAt(0);
  if (op == '%') {
    firstNo=firstNo.divide(new BigDecimal(100.0),m_format.getMaximumFractionDigits(),BigDecimal.ROUND_HALF_UP);
    m_number=firstNo;
  }
  if (!st.hasMoreTokens())   return m_number;
  token=st.nextToken();
  Number secondNumber;
  try {
    secondNumber=m_format.parse(token);
  }
 catch (  ParseException pe2) {
    log.log(Level.SEVERE,"Calculator.evaluate - token: " + token,pe2);
    m_number=new BigDecimal(0.0);
    return m_number;
  }
  BigDecimal secondNo=new BigDecimal(secondNumber.toString());
  char op2=0;
  if (st.hasMoreTokens()) {
    token=st.nextToken();
    if (OPERANDS.indexOf(token) == -1) {
      log.log(Level.SEVERE,"Calculator.evaluate - Unknown token: " + token);
      return m_number;
    }
    op2=token.charAt(0);
  }
  if (op2 == '%')   secondNo=secondNo.divide(new BigDecimal(100.0),m_format.getMaximumFractionDigits(),BigDecimal.ROUND_HALF_UP);
switch (op) {
case '/':
    m_number=firstNo.divide(secondNo,m_format.getMaximumFractionDigits(),BigDecimal.ROUND_HALF_UP);
  break;
case '*':
m_number=firstNo.multiply(secondNo);
break;
case '-':
m_number=firstNo.subtract(secondNo);
break;
case '+':
m_number=firstNo.add(secondNo);
break;
default :
break;
}
return m_number.setScale(m_format.getMaximumFractionDigits(),BigDecimal.ROUND_HALF_UP);
}

private BigDecimal evaluate ( ) { if ( m_display == null || m_display . equals ( "" ) || m_display . equals ( "0" ) ) { m_number = new BigDecimal ( 0.0 ) ; return m_number ; } StringTokenizer st = new StringTokenizer ( m_display , OPERANDS , true ) ; String token = st . nextToken ( ) ; if ( token . equals ( "-" ) ) { if ( st . hasMoreTokens ( ) ) token += st . nextToken ( ) ; else { m_number = new BigDecimal ( 0.0 ) ; return m_number ; } } Number firstNumber ; try { firstNumber = m_format . parse ( token ) ; } catch ( ParseException pe1 ) { log . log ( Level . SEVERE , "Calculator.evaluate - token: " + token , pe1 ) ; m_number = new BigDecimal ( 0.0 ) ; return m_number ; } BigDecimal firstNo = new BigDecimal ( firstNumber . toString ( ) ) ; m_number = firstNo ; if ( ! st . hasMoreTokens ( ) ) return m_number ; token = st . nextToken ( ) ; if ( OPERANDS . indexOf ( token ) == - 1 ) { log . log ( Level . SEVERE , "Calculator.evaluate - Unknown token: " + token ) ; return m_number ; } char op = token . charAt ( 0 ) ; if ( op == '%' ) { firstNo = firstNo . divide ( new BigDecimal ( 100.0 ) , m_format . getMaximumFractionDigits ( ) , BigDecimal . ROUND_HALF_UP ) ; m_number = firstNo ; } if ( ! st . hasMoreTokens ( ) ) return m_number ; token = st . nextToken ( ) ; Number secondNumber ; try { secondNumber = m_format . parse ( token ) ; } catch ( ParseException pe2 ) { log . log ( Level . SEVERE , "Calculator.evaluate - token: " + token , pe2 ) ; m_number = new BigDecimal ( 0.0 ) ; return m_number ; } BigDecimal secondNo = new BigDecimal ( secondNumber . toString ( ) ) ; char op2 = 0 ; if ( st . hasMoreTokens ( ) ) { token = st . nextToken ( ) ; if ( OPERANDS . indexOf ( token ) == - 1 ) { log . log ( Level . SEVERE , "Calculator.evaluate - Unknown token: " + token ) ; return m_number ; } op2 = token . charAt ( 0 ) ; } if ( op2 == '%' ) secondNo = secondNo . divide ( new BigDecimal ( 100.0 ) , m_format . getMaximumFractionDigits ( ) , BigDecimal . ROUND_HALF_UP ) ; switch ( op ) { case '/' : m_number = firstNo . divide ( secondNo , m_format . getMaximumFractionDigits ( ) , BigDecimal . ROUND_HALF_UP ) ; break ; case '*' : m_number = firstNo . multiply ( secondNo ) ; break ; case '-' : m_number = firstNo . subtract ( secondNo ) ; break ; case '+' : m_number = firstNo . add ( secondNo ) ; break ; default : break ; } return m_number . setScale ( m_format . getMaximumFractionDigits ( ) , BigDecimal . ROUND_HALF_UP ) ; }
evaluate . - evaluate info in display and set number
