title: BlackBerry Math Utilities (Pow & Round)
body: <p>I'm creating an application from an Excel application that I've used for several years, to calculate mortgage loan details, but I'm having problems with three calculations involving MathUtilities.pow &amp; MathUtilities.round. </p>
  
  <p>Here's my app &amp; the compile error messages that are giving me problems. I've also included my original Excel calculations as reference to what I am trying to calculate using MathUtilities. </p>
  
  <p>Would appreciate some guidance to resolve the problems.</p>
  
  <pre><code>import net.rim.device.api.system.Bitmap;
  import net.rim.device.api.ui.FieldChangeListener;
  import net.rim.device.api.util.MathUtilities;
  import net.rim.device.api.ui.text.NumericTextFilter;
  import net.rim.device.api.ui.text.TextFilter;
  import net.rim.device.api.ui.Graphics;
  import net.rim.device.api.ui.MenuItem;
  import net.rim.device.api.ui.FieldChangeListener;
  import net.rim.device.api.ui.component.BitmapField;
  import net.rim.device.api.ui.component.CheckboxField;
  import net.rim.device.api.ui.component.EditField;
  import net.rim.device.api.ui.component.LabelField;
  import net.rim.device.api.ui.component.Menu;
  import net.rim.device.api.ui.component.ObjectChoiceField;
  import net.rim.device.api.ui.component.NumericChoiceField;
  import net.rim.device.api.ui.component.PasswordEditField;
  import net.rim.device.api.ui.container.HorizontalFieldManager;
  import net.rim.device.api.ui.component.ButtonField;;
  import net.rim.device.api.system.Display;
  import net.rim.device.api.ui.Color;
  import net.rim.device.api.ui.Field;
  import net.rim.device.api.ui.Font;
  import net.rim.device.api.ui.FontFamily;
  import net.rim.device.api.ui.Ui;
  import net.rim.device.api.ui.UiApplication;
  import net.rim.device.api.ui.component.SeparatorField;
  import net.rim.device.api.ui.container.MainScreen;
  
  public class LoginSuccessScreen extends MainScreen implements FieldChangeListener {
  
  double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;       
  
          EditField mortamt;
          EditField air;
          NumericChoiceField amort;
          NumericChoiceField term;
          ObjectChoiceField freq;
          ButtonField calcButton = null;
  
           public LoginSuccessScreen(String username) {
                  add(new LabelField("Logged in!"));
                  add(new LabelField("Username: " + username));
  
                 add(new SeparatorField());
  
                  TextFilter numeric = new NumericTextFilter(NumericTextFilter.ALLOW_DECIMAL);
  
                  mortamt = new EditField("", "");
                  LabelField mortamtLabel = new LabelField("Mortgage Amount:    $ ", Field.FIELD_LEFT);
                  air = new EditField("", "");
                  air.setFilter(numeric);
                  LabelField airLabel = new LabelField("Annual Interest Rate:% ", Field.FIELD_LEFT);              
                  amort = new NumericChoiceField("",1,35,1,19);
                  LabelField amortLabel = new LabelField("Amortization:(Years)", Field.FIELD_LEFT);
                  term = new NumericChoiceField("",1,35,1,19);
                  LabelField termLabel = new LabelField("Mortgage Term: (Years)", Field.FIELD_LEFT);
                  freq= new ObjectChoiceField("", new String[] {"Weekly", "Bi-Weekly","Semi-Monthly", "Monthly"});
                  LabelField freqLabel = new LabelField("Payment Frequency:", Field.FIELD_LEFT);
  
  
                  add(new SeparatorField());
  
                  add(new SeparatorField());
                  GridFieldManager gridFieldManager = new GridFieldManager(2, 0);
                  gridFieldManager.add(mortamtLabel);
                  gridFieldManager.add(mortamt);
                  gridFieldManager.add(airLabel);
                  gridFieldManager.add(air);
                  gridFieldManager.add(amortLabel);
                  gridFieldManager.add(amort);
                  gridFieldManager.add(termLabel);
                  gridFieldManager.add(term);
                  gridFieldManager.add(freqLabel);
                  gridFieldManager.add(freq);
  
                  add(gridFieldManager);
  
                  calcButton = new ButtonField("Calculate Amounts:", ButtonField.CONSUME_CLICK);
                  calcButton.setChangeListener(this);
                  add(calcButton);  
  
              }
                  public void fieldChanged(Field field, int context) {
                  if (calcButton == field) {         
          }      
  
                  int a = Integer.parseInt(mortamt.getText());
                  add(new LabelField("Principal Amount: $" + a)); 
  
                  int b = Integer.parseInt(amort.getChoice(amort.getSelectedIndex()).toString());
                  add(new LabelField("Period to Amortization " +b * 12 + " months"));
  
                  double c = Float.parseFloat(air.getText()) / 100.;
                  add(new LabelField("AIR: %" + c));
  
                  add(new LabelField("Monthly Interest Factor %" + d));
                  double d = MathUtilities.pow(MathUtilities.pow((1+(c/2)), 2), 1/12) - 1;
  
                  add(new LabelField("EAR: "  +e ));               
                  double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;
  
                  add(new LabelField("Monthly Payment: $" + f));
                  double f = ((a*d)/(MathUtilities.pow(1-(1+d)) -c));
  
                  add(new SeparatorField());   
               }   
              }
  </code></pre>
  
  <p>ERROR MESSAGES:</p>
  
  <pre><code>Building UiFun
  C:\Research In Motion\BlackBerry JDE 4.5.0\bin\rapc.exe  -quiet import="..\Research In Motion\BlackBerry JDE 4.5.0\lib\net_rim_api.jar" codename=UiFun UiFun.rapc warnkey=0x52424200;0x52525400;0x52435200 "C:\Mortgage Calculator\res\apress_logo.png" "C:\Mortgage Calculator\res\login_arrow.png" "C:\Mortgage Calculator\res\login_icon.png" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomButtonField.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomDialog.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomLabelField.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\CustomObjectChoiceField.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\GridFieldManager.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\UiFunApplication.java" "C:\Mortgage Calculator\src\com\beginningblackberry\uifun\UiFunMainScreen.java"
  C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:102: cannot find symbol
  symbol  : method pow(double,int)
  location: class net.rim.device.api.util.MathUtilities
                  double d = MathUtilities.pow(MathUtilities.pow((1+(c/2)), 2), 1/12) - 1;
                                                            ^
  C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:105: cannot find symbol
  symbol  : method pow(double,int)
  location: class net.rim.device.api.util.MathUtilities
                  double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;
                                                                     ^
  C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:105: cannot find symbol
  symbol  : method round(int)
  location: class net.rim.device.api.util.MathUtilities
                  double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;
                                                ^
  C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:105: inconvertible types
  found   : net.rim.device.api.util.MathUtilities.round
  required: float
                  double e =(float)MathUtilities.round((MathUtilities.pow(1+d,12)-1) * 10000 ) / 10000;
                                                      ^
  C:\Mortgage Calculator\src\com\beginningblackberry\uifun\LoginSuccessScreen.java:108: cannot find symbol
  symbol  : method pow(double)
  location: class net.rim.device.api.util.MathUtilities
                  double f = ((a*d)/(MathUtilities.pow(1-(1+d)) -c));
                                                  ^
  5 errors
  Error!: Error: java compiler failed: javac -source 1.3 -target 1.1 -g -O -d C:\Users\ALEXMC~1\AppData\Local\Temp\rapc_1c2f4822.dir -boot ...
  Error while building project
  </code></pre>
  
  <p>The original Excel calculations are:</p>
  
  <pre><code>((1+(air/2)^)^(1/12)-1
  
  (
  </code></pre>