好,所以我不明白为什么它说该方法没有被本地使用....私人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:请参阅修改。 –
对不起,应该说有构造函数...它只会格式化传入它的数字,它将用于格式化区域和周长。 –