I am trying to get a decimal input from the keyboard, and it is just not working. First I tried
double d = Integer.parseInt(JOptionPane.showInputDialog(
"Please enter a number between 0 and 1:"));
and that obviously didn't work very well.
I am used to just parsing int's as they come in from the keyboard right into a variable, but I don't know what I am supposed to do for decimals! I need to be able to take a decimal like .9 straight from the keyboard and be able to have it in a variable I can do calculations with.
I know this is a basic question, but I need some help. Thanks!
I would use the Double class rather than the Integer class
double d = Double.parseDouble((String)JOptionPane.showInputDialog("Please enter a number between 0 and 1:"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With