This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem in Decimal Percent Formating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in Decimal Percent Formating" Watch "Problem in Decimal Percent Formating" New topic
Author

Problem in Decimal Percent 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);
}

}
}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

First of all, please use code tags when you post code, so that the forum automatically formats your code properly so that it's much easier to read.

You get the syntax error because your placement of { and } braces is wrong. You are now declaring a public static final member variable and a method inside your main() method. You can't do that. Those things have to be at class level, not inside the main() method. There are other errors as well, for example, what is getProperty()? You don't have a getProperty() method in your class.

It should look like this (note, I didn't test if this compiles):


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Decimal Percent Formating
 
Similar Threads
Help! With the formatting of the percent!
Prob in Decimal formating
number format
Format number
Reduce scale of BigDecimal to that required to represent exactly?