Results 1 to 6 of 6
  1. #1
    azurovyhrosik is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default convert String to Double

    Hi,
    how can I conver String to Double?

    It doesn't work:

    double d = Double.valueOf(str).doubleValue();

    CLDC 1.1
    MIDP 2.1

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    It doesn't work:
    Please explain.

  3. #3
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Works for me...

    I tried the following code (shamefully a cut & Paste) and it worked fine for me:
    Java Code:
    import java.io.*;
    import java.lang.*;
    
    public class StringToDouble{
      public static void main (String[] args) throws IOException{
        BufferedReader bff= new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter numeric type string value:");
        String num = bff.readLine();
        try{
          double d = Double.valueOf(num.trim()).doubleValue();
          System.out.println("double d = " + d);
        }
        catch (NumberFormatException e){
          System.out.println("NumberFormatException: " + e.getMessage());
        }
      }
    }
    So...
    • let's see your code
    • what is the problem you're seeing?

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #4
    azurovyhrosik is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Default

    Than you! I've found it :)
    now it works:

    n1 = Double.valueOf(a.getString()).doubleValue();

    I had only:

    n1 = Double.valueOf(a).doubleValue(); so that was the problem.

    Thank for your help!!
    Last edited by azurovyhrosik; 10-21-2008 at 11:56 PM.

  5. #5
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default That's great, now...

    Great!!! Now mark your post as solved.
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    What is the type of the variable a?

    One would assume that the type of a variable named str was String.

Similar Threads

  1. Replies: 7
    Last Post: 01-12-2008, 09:02 PM
  2. Converting String to Double
    By srini in forum New To Java
    Replies: 1
    Last Post: 12-24-2007, 08:03 PM
  3. convert string to a double?
    By javaMike in forum Advanced Java
    Replies: 2
    Last Post: 11-27-2007, 03:10 AM
  4. Replies: 2
    Last Post: 11-16-2007, 01:24 PM
  5. Help with convert a double type number
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 08:48 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
  •