2013-03-02 91 views
-1

我收到數字格式異常錯誤..要比較存儲在數據庫中的值作爲字符串值。下面代碼中「百分比」的值將是+ 10.05%或-10.05%,「 percentabove」值會像11.05和‘percentbelow’值是10.00 ..數字格式異常錯誤

代碼:

percentabove = cursor.getString(cursor.getColumnIndex(DBConstants.PERCENTABOVE)); 
percentbelow = cursor.getString(cursor.getColumnIndex(DBConstants.PERCENTBELOW)); 
     }while(cursor.moveToNext()); 

     double newprice= Double.parseDouble(percent); 
     double maxprice = Double.parseDouble(percentabove); 
     double minprice = Double.parseDouble(percentbelow); 


     if(newprice>maxprice || newprice<minprice) 
     { 

      String status=""; 
      if(newprice>maxprice) 
      { 
       status="Up"; 
      } 
      else if(newprice<minprice) 
      { 
       status="Down"; 
      } 

有format..Can我們使用的DecimalFormat任何建議更改格式雙到其他數據類型?

+0

你檢查你有什麼與此? double newprice = Double.parseDouble(percent); – 2013-03-02 08:08:53

+0

請編輯你的問題與你正在綁定解析的字符串的真實例子。 – Simon 2013-03-02 08:32:35

回答

0

NumberFormatException明確指出這個e xception是:

拋出以表明應用程序試圖將字符串轉換爲其中一種數字類型,但該字符串沒有適當的格式。

正如在評論中指出的,你是否試圖探索的價值percent,perceabove,percentbelow?也許值需要一些清理(修剪的價值,刪除額外的逗號等)