Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-17-2008, 12:03 AM
Java Tip's Avatar
Moderator
 
Join Date: Nov 2007
Posts: 1,691
Rep Power: 5
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Default Parsing a number using a NumberFormat
Code:
import java.text.NumberFormat;
import java.text.ParseException;

/*
 * Parse a number using a NumberFormat.
 */
public class NumFormatParse {
  //+
  /** A number to parse */
  public static final String input = "4096.251";
  //-

  /** The main (and only) method in this class. */
  public static void main(String[] av) { 

    //+
    NumberFormat defForm = NumberFormat.getInstance();

    try {
      Number d = defForm.parse(input);
      System.out.println(input + 
        " parses as " + d +
        " and formats as " + defForm.format(d));
    } catch (ParseException pe) {
      System.err.println(input + "not parseable!");
    }
    
  }
}
__________________
"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing URL in Java Java Tip java.net 0 04-07-2008 09:14 PM
Using SAXParserFactory for parsing XML Java Tip Java Tips 0 03-20-2008 10:42 AM
Parsing URL Java Tip Java Tips 0 12-26-2007 11:16 AM
Parsing XML documents using DOM JavaForums Java Blogs 0 11-19-2007 05:30 PM
Parsing XML Documents-1 (DOM and SAX) JavaForums Java Blogs 0 11-10-2007 11:41 PM


All times are GMT +2. The time now is 07:49 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org