【发布时间】:2015-02-12 12:09:52
【问题描述】:
所以我在格式化字符串时遇到了问题。
我的输出应该总是##.##C or F(温度转换)
这是我的方法:
public void setResultLabel(double inNumber, char inChar)
{
String number, letter;
number = String.valueOf(inNumber);
letter = String.valueOf(inChar);
String temp;
temp = number + letter;
String format = String.format("%2.5s", temp); /* how do you make this code
so that the out put result will always be up to two decimal places
with a char C or F? */
result.setText(format);
add(result);
}
【问题讨论】: