这是我的代码:
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 设置为 double 值,但我不能,因为 JOptionPane 仅保存字符串。我该如何在仍然使用对话框的情况下执行此操作?任何有效的答案都会受到赞赏。谢谢。
最佳答案
几天前我也遇到了类似的问题。
我使用 Double.parseDouble() 将变量解析为 String ,来自 double
我认为代码应该如下所示......
double currentSalary = Double.parseDouble(JOptionPane.showInputDialog(frame, "Enter your current salaryy\", \"Current Salary\", JOptionPane.PLAIN_MESSAGE, null, null, \"Numbers only!\""));
如果我错了,请随时纠正我,我只是一个初学者,但这对我有用!
关于java - 如何将 "double"值与 JOptionPane.showInputDialog 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39758916/