Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding to 2 decimal places 1

Status
Not open for further replies.

rocknrisk

Programmer
May 14, 2002
43
GB
Hi all,

Please look at this code:

jbtnAddVAT.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
double addOriginal = (Double.parseDouble(jtxtAddVAT.getText()));
double addFinal = (addOriginal + (addOriginal * 17.5 / 100));
jlblAddVAT.setText("£ " + addFinal);
}
});

Basically, the user types an amount into a JTextField, clicks a JButton and the amount minus VAT is displayed in a JLabel. Everything works fine except, the amount, I want, displayed must be in currency (i.e.: 2 decimal places - rounded up).

So, I guess, my question would be "What do I have to do to the above code to accomplish this?".

Any help will be greatly appreciated. I have looked at the few questions/answers relating to this topic on this forum but nothing really answers my question. I'm thinking, "surely the Double class will have a rounding feature", but I cannot find any such method. Help please.

Thank you in advance.
Clinton


"The important thing is not to stop questioning." - Albert Einstein
 
see java.text.DecimalFormat class

-pete
[sub]I just can't seem to get back my IntelliSense[/sub]
 
Pete,

You're a star, mate. Thank you.

"The important thing is not to stop questioning." - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top