get the Double Value from String


Last Updated:

  1. joevj

    joevj Member This Topic's Starter

    Joined:
    Nov 1, 2010
    Messages:
    18
    Likes Received:
    1
    Hi All,

    I am not an expert in Java and i'm rather new to Android development as well.

    I am unable to extract the double value from a string... here is my code..

    Code (Text):
    1.  
    2.             String str;
    3.             double amount;
    4.            
    5.             final EditText txtAmount = (EditText) findViewById(R.id.entryAmount);
    6.             str = txtAmount.getText().toString();
    7.  
    8.             amount = (double)str;
    9. //            amount =   parseDouble(str);
    10.  
    11.  
    I tried to cast by (double) and tried parseDouble. None of my trials are working.

    Can you help?

    Regards
    Joe


    Is it a wrong location. Now I think I should posted a level below. But not able to remove !!
     

    Advertisement
  2. JiMMaR

    JiMMaR Well-Known Member

    Joined:
    Jun 12, 2010
    Messages:
    363
    Likes Received:
    57
    you gotta use parse like this

    amount = Double.parseDouble(str);
     
    joevj likes this.
  3. joevj

    joevj Member This Topic's Starter

    Joined:
    Nov 1, 2010
    Messages:
    18
    Likes Received:
    1
    Thanks JiMMar. Now it works really nice!
     

Share This Page

Loading...