954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Applet Rounding Issue

Need help rounding. MoPay.setText is showing up as .########### (I'm new to this language.) Oh, and my dollar sign isn't showing up, does anyone no why?


public void actionPerformed(ActionEvent e)
{
int Mort;
double Int;
int T;

if(e.getSource()==Reset)
{
answer.setText("");
answera.setText("");
answerb.setText("");
MoPay.setText("");
}

else if(e.getSource()==Calculate)
{
try {
Mort = Integer.parseInt(answer.getText());
Int = Double.parseDouble(answera.getText());
T = Integer.parseInt(answerb.getText());
MoPay.setText("$" + (Int - (Mort * Int * T)) / (T*12));

}
catch(java.lang.NumberFormatException NFE)
{
Mort = 0;
Int = 0;
T = 0;
}
}
}

anbarblue
Newbie Poster
5 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

If I were you I'd start with using proper Java naming conventions, so variable and method names using CamelCase and starting with a lowercase letter, class and interface names similar but starting with an uppercase letter.
Also use meaningful names for your variables and members to make it easier to comprehend what's going on.

What is "Calculate", what is "Reset", etc. etc.?
Are you sure you're intending to use a comparison of the reference values there rather than a comparison of content?
Are you sure that your math is correct? Isn't there an implicit cast somewhere which is causing you to loose precision?

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You