The moose likes Java in General and the fly likes Prob in Decimal formating Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Prob in Decimal formating" Watch "Prob in Decimal formating" New topic
Author

Prob in Decimal formating

Gagan Singh
Greenhorn

Joined: Dec 05, 2006
Posts: 2
Hi,
I m trying to make a method in which i want to format a fraction into percent format.
But i m unable to remove th errors in it.
If som1 can help me out...
below is the code i have written...

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.MessageFormat;
import java.text.NumberFormat;

public class formating {

public static void main(String[] args) {

BigDecimal number = 8.375; // This is the value I want to format
public static final String DEFAULT_PERCENT_FORMAT = "#0.0#";


public String formatPercent(BigDecimal amount) { // Its showing syntax error here

DecimalFormat format = null;
format = new DecimalFormat(getProperty(DEFAULT_PERCENT_FORMAT));
return format.format(amt);
}

}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
The brackets are nested incorrectly, so that the formatPercent method is now inside the main method. In Java, you can't declare a method inside of another method.


Android appsImageJ pluginsJava web charts
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Prob in Decimal formating
 
Similar Threads
Reduce scale of BigDecimal to that required to represent exactly?
number format
Format number
Problem in Decimal Percent Formating
setting precision for float values