I have the method below, but for some reason it is not formatting the area to have only one decimal. All help is appreciated.
public double beraknaArea()
{
DecimalFormat formatter = new DecimalFormat("#0.0");
double area = 0;
area = radie*radie*3.14;
formatter.format(area);
return area;
}
You are returning the same double, and not the output of the formatter.
The format() method does not alter the double that you pass in, it returns a String format of the double.
No methods in Java may change the type of a declared variable, or mutate any primitive value (or indeed String). You need to return what formatter.format(area) returns, not the unchanged value of area.
public String beraknaArea()
{
DecimalFormat formatter = new DecimalFormat("#0.0");
double area = radie*radie*3.14;
return formatter.format(area);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With