Results 1 to 2 of 2
  1. #1
    coolman50544 is offline Member
    Join Date
    Apr 2014
    Location
    Miami, FL
    Posts
    47
    Rep Power
    0

    Default A question about the NumberFormat class

    Hi I just have a quick question

    How come I can do this from the NumberFormat class

    float miles = 534.433434323F;

    String milesFormatted = NumberFormat.format(miles);

    System.out.println(milesFormatted);

    but not

    float miles = 534.433434323F;

    String milesFormatted = NumberFormat.getNumberInstance(3).format(miles);

    System.out.println(milesFormatted);


    I would appreciate a complete explanation of this concept. Thank you very much.

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,656
    Rep Power
    5

    Default Re: A question about the NumberFormat class

    I'm not certain what you are trying to do. Also, in the second example you are passing a integer to the getNumberInstance() method. That integer represents a Locale. Is that what you intended?

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. NumberFormat Class Question
    By SoullessWhale in forum New To Java
    Replies: 1
    Last Post: 10-22-2012, 11:07 AM
  2. A (very) simple question about NumberFormat in Applet
    By calnastic in forum New To Java
    Replies: 2
    Last Post: 06-17-2011, 03:34 AM
  3. NumberFormat which leave fractions as they are
    By itaipee in forum AWT / Swing
    Replies: 2
    Last Post: 12-09-2009, 06:11 PM
  4. using numberformat
    By roaan in forum New To Java
    Replies: 3
    Last Post: 07-02-2009, 04:28 AM
  5. NumberFormat is abstract?
    By DrKush in forum New To Java
    Replies: 4
    Last Post: 03-27-2009, 07:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •