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]
# 1

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));

}

pbrockway2a at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 2
It now comes back with an error saying illegal start of expression :S
T-mosea at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 3
On line 42?
pbrockway2a at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 4
42, which is the response to the big question: life, the universe and everything
jack@square6a at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 5

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)

T-mosea at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 6

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.

pbrockway2a at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 7

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 ));

}

T-mosea at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 8
Right at the very top of the file - line 1 or line 2, not line 325.
pbrockway2a at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 9
Thanks pbrockway2 its working great now. Thanks for everyones help
T-mosea at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...
# 10
> its working great now. Thanks for everyones helpExcellent! You're welcome.
pbrockway2a at 2007-7-11 23:56:33 > top of Java-index,Java Essentials,New To Java...