我试图弄清楚如何将总数四舍五入到小数点后两位。总数是一个 EditText。我不能把它缩小到小数点后两位。它有什么问题?谢谢你的帮助。
public void macro() {
caloriesTotal = Double.parseDouble(calories.getText().toString());
total = (caloriesTotal * .20)/9;
DecimalFormat round = new DecimalFormat ("###.##");
round.format(total);
carbsTotal = (caloriesTotal * .40)/4;
proteinTotal = (caloriesTotal * .40)/4;
fat.setText(Double.toString(total));
carbs.setText(Double.toString(carbsTotal));
protein.setText(Double.toString(proteinTotal));
}