Results 1 to 2 of 2

Thread: string to numeric

  1. #1

    Thread Starter
    Member Evolute's Avatar
    Join Date
    Sep 2002
    Location
    Portugal
    Posts
    58

    string to numeric

    Hi all

    How can i convert a string from a textbox to a numeric value?

    Thanks!
    Evolute

  2. #2
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    All numeric classes have a method parseClassType e.g. parseInt, parseFloat etc etc
    Code:
    try {
      int myValue = Integer.parseInt(textField.getText());
    }
    catch (NullPointerException npe) {
      // Thrown when the underlying document in the JTextField is null.
      npe.printStackTrace();
    }
    catch (NumberFormatException nfe) {
      // Thrown if the the text field has a value that can't be parsed to an integer.
      nfe.printStackTrace();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width