Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Instantiating NumberFormat Class

  1. Aug 8, 2014 #1
    I've imported java.util, java.text and placed the following method under an appropriate class.

    I'm unable to pinpoint why compiler can't instantiate the type NumberFormat in my method's second line

    public static void tailorFormat(String name, double value, Locale loc){

    NumberFormat kitty = new NumberFormat (loc); // <<<<< this is where I've referred to

    DecimalFormat shelter = (DecimalFormat) kitty;
    System.out.println(name + " " + value + " " + loc.toString());
  2. jcsd
  3. Aug 8, 2014 #2
    What is the error that the compiler is telling you?
    Usually (but not always) the compiler is actually quite helpful in telling you what you've done wrong :)
  4. Aug 8, 2014 #3


    Staff: Mentor

    java.text.NumberFormat is an abstract class, so you can't use it directly as you are trying to. Here's a sample of how this class can be used (see http://docs.oracle.com/javase/7/docs/api/java/text/NumberFormat.html): [Broken]
    The web page I linked to has several other examples that might be of help to you.
    Last edited by a moderator: May 6, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook