我正在尝试格式化此返回字符串以在小数点后显示评级。
return String.format(title + "," + genre + "," + releaseYear + "(" + (getRating() == -1 ? "No ratings" : getRating()) + "): " + numOfDeaths + " deaths");
我一直收到错误,说过的参数太少了。
答案 0 :(得分:1)
你想要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");