Here’s what I do:
double x = 7.0;
System.out.printf("%.2f", x);
Eclipse gives me this error “The method printf(String, Object[]) in the type PrintStream is not applicable for the arguments (String, double)”
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Are you using a version of Java older than 1.5? Or maybe an older compiler compliance setting in Eclipse? (e.g. 1.4) In fact, I am pretty sure that is the cause – I just switched my compliance setting to 1.4 and I get the same error as you.
Check your Project’s Compiler Compliance setting:
This will work once you are using Java 1.5 or higher, since the printf method was added in 1.5.