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