1.將最後的結果強制類型轉換 (double)x;2.那就String.valueOf(Integer.paserInt("200209")-1);要判斷特殊情況,比如月份是1的時候,還要捕捉異常

解决方案 »

  1.   

    如果不是标准时间格式,就用string和int之间的转化,转化成int后进行运算,然后再转回string (如果有必要)
      

  2.   

    看看BigDecimal和DateFormat或者SimpleDateFormat。
      

  3.   

    看看BigDecimal和DateFromat(或者SimpleDateFormat)。
      

  4.   

    double s = 19.6;
    double ss = s+s+s;
    double sss = new Double(ss).doubleValue();
    long ssss =new  Double(ss).longValue();
    float sssss = new Double(ss).floatValue();
    System.out.println(ss);
    System.out.println(sss);
    System.out.println(ssss);
    System.out.println(sssss);
    以下是输出结果,你应该用float类型来转换吧。
    58.80000000000000458.8000000000000045858.8
      

  5.   

    1。 n你可以确定一个最大精度啊。然后忽略精度后的字符2。 
    import java.util.*;
    import java.text.*;private String getPrevMonth(String month ) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMM");
        try{
            Calendar c = format.getCalendar();
            c.setTime(format.parse(month));
            c.add(Calendar.MONTH,-1);     
            return format.format(c.getTime());
        }catch(Exception e) {}
        return "";
    }