Converting Text from UITextField into an int? then making a calculation

Discussion in 'iOS Programming' started by Dylan552, Sep 1, 2010.

  1. Dylan552 macrumors newbie

    Joined:
    Sep 1, 2010
    #1
    I need a segment of code that takes a string from number.text and makes it in to a double. Which i can then use to make a calculation. I have tried many other soultion i found on tht site but all had errors or just didnt work.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Which site?

    What other solutions? Post some code.

    What errors? What didn't work? Be specific.
     
  3. kayloh20 macrumors regular

    Joined:
    Apr 8, 2010
    Location:
    Chicago, IL
    #3
    I have always just used:

    [textField.text intValue];

    or

    [textField.text doubleValue];

    The text property returns an NSString. If you look up NSString in the documentation, you will see in the long list of methods, that there is a section of methods labeled "Getting Numeric Values". The two above methods are there as well as a couple other ones (like boolean, long, etc.).
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Three simple rules of thumb:
    1. Post your code.
    2. Describe what you expected to happen.
    3. Describe what did happen. Include the actual text of any error messages.

    When you leave any of these out, we have to guess.
    Guessing is a remarkably bad debugging approach.

    A fourth rule:
    4. If you didn't write the code yourself, tell us exactly where you copied it from: a book (title & author), a website (give the URL), etc.
     

Share This Page