0
我需要格式化此浮點數,以便標籤顯示x小數點。 ex.10.9832432我希望它顯示10.9832432確切的小數位數。如何在java中將浮點數設置爲x的小數位數
try{
DecimalFormat df = new DecimalFormat("#");
float numOne = Float.parseFloat(numberOne.getText());
float numTwo = Float.parseFloat(numberTwo.getText());
float anser = numOne+numTwo;
String AR = df.format(anser);
answerLabel.setText(AR);
}catch(NumberFormatException nfe){
answerLabel.setText(null);
}
'float'只具有精度6位,我建議使用'double'或'BigDecimal' –