Results 1 to 2 of 2
Thread: Capping decimal places
- 12-20-2007, 08:07 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 8
- Rep Power
- 0
Capping decimal places
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.Java 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); }
- 12-20-2007, 09:28 PM #2
Similar Threads
-
round to two decimal places
By javaMike in forum New To JavaReplies: 3Last Post: 12-24-2011, 02:01 AM -
rounding double to two decimal places
By javaMike in forum Advanced JavaReplies: 15Last Post: 03-10-2010, 12:04 AM -
Java calculator decimal
By cart1443 in forum New To JavaReplies: 2Last Post: 04-16-2008, 01:19 PM -
How do I convert a decimal value to hexadecimal with double precision (64 bit)
By SKaur in forum New To JavaReplies: 7Last Post: 01-12-2008, 09:02 PM -
Converts a binary number to a decimal
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 09:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks