我正在通过为每次转换创建方法来创建一个英制到公制转换程序。我想将转换前后的数字格式化为两位小数。截至目前,它显示我“100英寸= 254厘米”。出了什么问题?
String strConversionChoice, strValue;
double dblInputValue;
int intConversionChoice;
strConversionChoice = txtInputConversionChoice.getText();
strValue = txtInputValue.getText();
DecimalFormat x = new DecimalFormat("###.##");
intConversionChoice = Integer.parseInt(strConversionChoice);
dblInputValue = Double.parseDouble(strValue);
if (intConversionChoice == 1) {
lblOutput.setText(x.format(dblInputValue) + " inches = " + x.format(inchesToCentimetres(dblInputValue))+ " centimetres");
}
else if (intConversionChoice == 2) {
lblOutput.setText(x.format(dblInputValue) + " feet = " +x.format(feetToCentimetres(dblInputValue)) + " centimetres");
}