好,所以我不明白爲什麼它說該方法沒有被本地使用....私人String formatNumber()方法是這樣說的。呼叫方法回合java
基本上我需要做的是有一個返回圓周 的方法 - 舍入的數字爲2位小數並返回一個字符串 另一種方法 - 和返回圓周的格式化版本的另一種方法...
不難看出我想要做什麼,但它給了我上述錯誤,我無法弄清楚。
//figures out circumference
public double getCircumference(){
circumference = 2 * Math.PI * radius;
return circumference;
}
//takes string and turns back into a double
public double getFormattedCircumference(){
double x = Double.parseDouble(format);
return x;
}
//this method is giving the error of not being used locally...
//method takes double and turns to string so that it can be formatted and it
has to be a string
private String formatNumber(double x){
x = circumference;
NumberFormat number = NumberFormat.getNumberInstance();
number.setMaximumFractionDigits(2);
String format = number.format(x);
return format;
}
好的。所以我必須設置它,以便getFormattedCircumference調用私有方法?對?那麼我實際上可以在主類中顯示正確的數字。 –
@Tobin:請參閱修改。 –
對不起,應該說有構造函數...它只會格式化傳入它的數字,它將用於格式化區域和周長。 –