Results 1 to 3 of 3

Thread: how to change inputted string to double?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    11

    Exclamation how to change inputted string to double?

    If I'm inputting a number in string format using JOptionPane.showInputDialog, how do I convert the string I inputted to a double?

    String rate;
    double hrRate;

    rate= JOptionPane.showInputDialog("Input hourly rate");

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Posts
    367
    String rate;
    double hrRate;

    hrRate= (new Double(JOptionPane.showInputDialog("Input hourly rate"))).doubleValue();


    So you are creating a Double object here and then asking for the double value of that object.
    Last edited by billrogers; Jun 26th, 2001 at 10:06 AM.

  3. #3
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    You can also do:

    Code:
    String rate = JOptionPane.showMessageDialog("Enter a number");
    Double hrRate = Double.parseDouble(rate);
    Alcohol & calculus don't mix.
    Never drink & derive.

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