View Single Post
  #1 (permalink)  
Old 12-20-2007, 10:07 PM
Rageagainst20 Rageagainst20 is offline
Member
 
Join Date: Dec 2007
Posts: 8
Rageagainst20 is on a distinguished road
Capping decimal places
Code:
int previous = Integer.parseInt(TxtPrevious.getText()); int current = Integer.parseInt(TxtCurrent.getText()); double cpu = 0.07; double quart = 20.00; if (current >= previous) { double sum = (current - previous) * cpu + quart; String sAnswer = Double.toString(sum); TxtResult.setText ("£" + sAnswer); } else { JOptionPane.showMessageDialog(null, "Current reading has to be greater than previous reading", "Billing Error", JOptionPane.ERROR_MESSAGE); }
The above code takes two values add's 0.07 and 20.00 to it and displays it in a textbox, I was wondering if there was anyway to "cap" the decimals to 2 deimcal places, aka currency format.
Reply With Quote
Sponsored Links