Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Convert Formatted String to Integer

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    19
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Convert Formatted String to Integer

    Hi,
    Appreciate any help on this issue.
    If I use the class DecimalFormat to format long number, how can I convert it back to integer?


    DecimalFormat longFormat = new DecimalFormat("#,###");  
    		long testLong=11000;
     
    		String strLong=longFormat.format(testLong);
    		System.out.println("NUM : " + strLong);
     
     
    		//Assume that at this point I don't have 
    		//testLong, I have only the strLong value...
    		long newLong=Long.parseLong(strLong) * 2;
     
    		//java.lang.NumberFormatException: For input string: "11,000


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Convert Formatted String to Integer

    Look at the parse method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2011
    Posts
    19
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Convert Formatted String to Integer

    Hi Norm,
    Can you be more specify?
    Is the conversion that I'm trying is not possible?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Convert Formatted String to Integer

    Did you try the DecimalFormat class's parse method?

    Did you post the String you are trying to convert?
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    liron50 (February 15th, 2014)

  6. #5
    Junior Member
    Join Date
    Apr 2011
    Posts
    19
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Convert Formatted String to Integer

    Hi,
    Thanks I used the parse method, and it seems working.

    long newlong= longFormat.parse(strLong).longValue();

Similar Threads

  1. Sequences (convert char[] to String) [Replacing String with Character]
    By tpolwort in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 25th, 2013, 02:56 PM
  2. Replies: 6
    Last Post: June 3rd, 2013, 04:57 AM
  3. How to convert String array to Integer array...?'
    By suyog53 in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 25th, 2012, 08:50 AM
  4. Replies: 2
    Last Post: March 17th, 2012, 04:12 PM
  5. Typecasting of double variable to integer
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 2
    Last Post: December 5th, 2010, 03:41 AM