2013-03-02 90 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?也许值需要一些清理(修剪的价值,删除额外的逗号等)