【发布时间】:2016-11-28 12:46:07
【问题描述】:
我编写了一个小测试,最后结果应该显示一个百分比。目前有三个问题,百分比几乎是正确的,例如。 2/3 将显示 66.0% 而不是 66.7 或 67。 百分比格式为双精度,分数格式为整数。这可能是一个原因吗? 我也尝试过在 settext 中进行计算,但这不起作用。因此我发明了百分比变量。
...
else{
//neue Frage oder Testende
if(durchlauf < 3){
SetNextQuestion();
}
else{
qt.setText("");
rdg.setVisibility(View.INVISIBLE);
hintbutton.setVisibility(View.INVISIBLE);
percentage = ((score * 100) / 3 );
t.setText("Test abgeschlossen \n" + "Punkte: " + score + " (" + String.format("%.2f", percentage) + "%)");
}
【问题讨论】:
标签: android string format settext