Using currency format to round results (error cannot find symbol)
Hi i have a small program that converts currency and want to round the numbers up to 2 d.p i have chosen to use the command
numberFormat(txtOutput, "0.00");
But i cannot figure out where to put it in my program as it just returns errors like cannot find symbol. Could anyone please help?
this is the program that it is going to go into
double x;
double y;
double z;
x = Integer.parseInt(txtInput.getText());
y = 0.748279;
z = Double.parseDouble(txtExchange.getText());
if (z > 0)
txtOutput.setText('€' + Double.toString( x * z ));
else
txtOutput.setText('€' + Double.toString( x * y ));
[679 byte] By [
T-mosea] at [2007-11-27 1:19:56]

import java.text.DecimalFormat;
//...
DecimalFormat df = new DecimalFormat("0.00");
double x = Integer.parseInt(txtInput.getText());
double y = 0.748279;
double z = Double.parseDouble(txtExchange.getText());
if(z > 0) {
txtOutput.setText('€' + df.format(x * z));
} else {
txtOutput.setText('€' + df.format(x * y));
}
Compiling 1 source file to C:\Documents and Settings\Tom\My Documents\Computer Science Work\CO1223-Object Orientated Programming\Assignment01\Assignment\build\classes
C:\Documents and Settings\Tom\My Documents\Computer Science Work\CO1223-Object Orientated Programming\Assignment01\Assignment\src\Converter.java:325: illegal start of expression
import java.text.DecimalFormat;
1 error
BUILD FAILED (total time: 0 seconds)
Discretion is the better part of valour, T-mose. And you did well not to post all 325+? lines of code.
One thing did occur to me: it is very unusual for import statements to occur at this position. Perhaps the lineimport java.text.DecimalFormat;
could go near the top. Say the first or second line.
I now have this but it is still returning the error illegal start of expression for the line "import java.text.DecimalFormat;". And i have checked the braces and they appear correct
import java.text.DecimalFormat;
numberFormat(txtOutput, "0.00");
DecimalFormat df = new DecimalFormat("0.00");
double x = Integer.parseInt(txtInput.getText());
double y = 0.748279;
double z = Double.parseDouble(txtExchange.getText());
if (z > 0){
txtOutput.setText('€' + df.format( x * z ));
} else {
txtOutput.setText('€' + df.format( x * y ));
}