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");
Printable View
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");
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.
You can also do:
Code:String rate = JOptionPane.showMessageDialog("Enter a number");
Double hrRate = Double.parseDouble(rate);