Results 1 to 3 of 3
- 01-21-2009, 01:58 AM #1Member
- Join Date
- Jan 2009
- Rep Power
I have a program which does some stuff for a payroll (this is only an exercise for me).
Well, I'm using doubles as my variable Type. However, whenever i'm displaying the money, it is showing the actual pay, which is showing 3 decimal places. How can I eliminate all of the decimals past the 2nd?
Thanks! Please remember I'm a beginner!
- 01-21-2009, 03:37 AM #2
We have the String.format method and the Formatter class in j2se 1.5+:
double d = 1.0/3.0; System.out.println("d = " + d); String s = String.format("%.2f", d); System.out.println("s = " + s); // Another way. System.out.printf("formatted d = %.2f%n", d); // Trick not recommended for $ double f = ((int)(d * 100))/100; System.out.println("f = " + f);
- 01-21-2009, 10:39 AM #3
- By greenbean in forum New To JavaReplies: 10Last Post: 01-12-2009, 08:39 AM
- By fishtoprecords in forum New To JavaReplies: 3Last Post: 11-28-2008, 07:05 AM
- By javanub in forum New To JavaReplies: 1Last Post: 11-23-2008, 12:11 PM
- By new person in forum New To JavaReplies: 1Last Post: 11-17-2008, 10:01 PM
- By dunff2k in forum SWT / JFaceReplies: 1Last Post: 11-14-2008, 03:26 PM