Double.parseDouble(display.getText())
所有字符串一律转换成Double型的,就不用去判断了.

解决方案 »

  1.   

    float和double只能用来做科学计算或者是工程计算,在商业计算中我们要用java.math.BigDecimal
    你可以先把你要表示的数转为String
    然后用new BigDecimal(string).floatValue();
    这样就得到float数的精确表示了
      

  2.   

    先谢谢大家,但我想问的不是用什么来实现更好,我只想知道,为什么我这样写,会出现我的问题?请给余解释!!见下:
    if(text.getText().indexOf(".")== -1)
    { if(num.indexOf(".")==-1)
    { text.setText(""+(Long.parseLong(text.getText())+Long.parseLong(num)));}

    else if(text.getText().indexOf(".")!= -1 || num.indexOf(".")!=-1)
    { text.setText(""+(Double.parseDouble(text.getText())+Double.parseDouble(num))); }以上是我的处理 + 法,当作整数的时候,没有问题,担当我做9.2+0.2的时候,却为9.39999999,请问为什么会这样啊??
    if(text.getText().indexOf(".")== -1)
    { if(num.indexOf(".")==-1)
    { text.setText(""+(-(Long.parseLong(text.getText())-Long.parseLong(num))));}

    else if(text.getText().indexOf(".")!= -1 || num.indexOf(".")!=-1)
    { (-(Double.parseDouble(text.getText())-Double.parseDouble(num)))); }
    以上,使我的 - 法处理,可是如果,我不再text.settext(""+(-............))),如果,我不加上这个负号,出来的结果是负数??而且,同样我也输入9.2-0.5的时候,却不象加法一样,而是出现8.7这样的实际数字。??