2016-09-28 45 views
0

这是我的代码:我怎么用“双重”价值与JOptionPane.showInputDialog

 currentSalary = (double)(JOptionPane.showInputDialog(frame, "Enter your current salary", "Current Salary", JOptionPane.PLAIN_MESSAGE, null, null, "Numbers only!")); 
     raise = currentSalary * .04; 
     total = currentSalary + raise; 
     NumberFormat money = NumberFormat.getCurrencyInstance(); 
     System.out.println("Your raise is " + money.format(total)); 

目前,我需要currentSalary双重价值,但我不能,因为JOptionPane中仅持有字符串。在仍然使用对话框的情况下,我该如何去做这件事?任何工作答案表示赞赏。谢谢。

+0

Double.parse()。 – nhouser9

+0

解析方法(对象)未定义为类型Double是它给我的东西 – dirtydan

+1

https://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#parseDouble(java.lang .String) – nhouser9

回答

3

就在前几天我也遇到过类似的问题。

我用Double.parseDouble()来分析变量字符串,从

的代码应该看起来像下面我想......

  double currentSalary = Double.parseDouble(JOptionPane.showInputDialog(frame, "Enter your current salaryy\", \"Current Salary\", JOptionPane.PLAIN_MESSAGE, null, null, \"Numbers only!\"")); 

感觉免费纠正我,如果我错了,我只是一个初学者,但这对我有用!

+1

不,不要担心,这是正确的。 =) – XenoRo

+0

谢谢你,别担心,我是一个初学者太哈哈。 – dirtydan