• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Problem in Decimal Percent Formating

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}

}
}
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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):
 
I guess I've been abducted by space aliens. So unprofessional. They tried to probe me with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic