String a = "1000000000";float b = Float.parseFloat(a);System.out.println(b);
会输出  1.0E8我现在想输出正常的数字,怎么解决?

解决方案 »

  1.   

    DecimalFormat df = new DecimalFormat("0.##");
    df.format(v1);
      

  2.   

    you can using String#format when you use JDK1.5
    such as;
    System.out.println(String.format("%1f",b));
      

  3.   

    /**
       * 格式化欄位值
       * @param sValue 原欄位值
       * @param cType 欄位數據類型
       * @return 整理後的欄位值
       */
      public static String formatField(String sValue, char cType) {
        String sDefault;
        switch (cType) {
          case 'N': sDefault = "0"; break;
          case 'P': sDefault = "0.00"; break;
          default: sDefault = "";
        }
        if (sValue == null || "".equalsIgnoreCase(sValue) || "null".equalsIgnoreCase(sValue)) {
          sValue = sDefault;
        } else {
          sDefault = sValue;
          switch (cType) {
            case 'D':
              sValue = convertDate(sDefault);
              break;
            case 'N':
              sValue = (new DecimalFormat("#,##0")).format(Double.parseDouble(sDefault));
              break;
            case 'P':
              sValue = (new DecimalFormat("#,##0.00")).format(Double.parseDouble(sDefault));
              break;
          }
        }
        return sValue;
      }