【发布时间】:2013-12-02 17:00:42
【问题描述】:
我遇到了一个小问题,即我的程序只在需要小数时才接受点。
我不会用逗号替换点,而是我想让它同时接受点和逗号。我需要将其应用于字符串“金额”,然后将其转换为双倍!帮帮帮帮! 问候奥利弗
public static void main(String[] args){
double euro, usd, gpb, dkk, done;
Scanner input = new Scanner(System.in);
String temp = JOptionPane.showInputDialog("Convert from " +"USD, GBP, DKK or EURO?");
String tempp = JOptionPane.showInputDialog("To " +"USD, GBP, DKK or EURO?");
Map<String, Double> lookUpMap = new HashMap<String, Double>(){{
put("EURO", new Double(7.46));
put("USD", new Double(5.56));
put("GBP", new Double(8.84));
put("DKK", new Double (1.0));
}};
String amount = JOptionPane.showInputDialog("amount of " +(temp));
double amountt = Double.parseDouble(amount);
done = (lookUpMap.get(temp.toUpperCase()) / lookUpMap.get(tempp.toUpperCase())) * amountt;
JOptionPane.showMessageDialog(null, "It is " +done + " " +(temp),"Final amount of " + (temp), JOptionPane.PLAIN_MESSAGE);
String exit = JOptionPane.showInputDialog("Do u want to rerun program? YES or NO");
if(exit.equalsIgnoreCase("YES")){
RerunGUI.main(args);
}else{
System.out.println("");
}
}
}
【问题讨论】:
-
点和小数有什么区别?请更清楚地说明您需要完成的工作
-
@DoubleDouble 我实际上将它理解为 Ijgw(或者它是 ljgw?)理解它的方式,其中逗号与小数点相同。
-
@Quincunx 是的,这更有意义。删除评论,因为它现在没有帮助。
-
顺便说一句,您永远不应该使用浮点数或双精度数来表示金钱。 stackoverflow.com/questions/3730019/…