0

I am trying to format this return string to display ratings at one decimal place.

return String.format(title + "," + genre + "," + releaseYear + "(" + (getRating() == -1 ? "No ratings" : getRating()) + "): " + numOfDeaths + " deaths");

I keep getting an error saying too few parameters passed.

2
  • 1
    show us full code Commented Oct 27, 2016 at 14:18
  • Been a while since I spoke Java but I think format takes multiple arguments. title, genre, releaseYear etc should be arguments. On the other hand, you should probably be able to simply do a "return title + "," + genre + "," + ... Commented Oct 27, 2016 at 15:49

1 Answer 1

1

You want java.text.DecimalFormat.

DecimalFormat df = new DecimalFormat("0.0##");
String result = df.format(getRating());
return String.format(title + "," + genre + "," + releaseYear + "(" + (getRating() == -1 ? "No ratings" : result) + "): " + numOfDeaths + " deaths");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.