Java.lang.numberformatexception:无效的浮点“0.008466”

时间:2016-03-08 16:39:54

标签: java android numberformatexception

我只是从php请求获得0.008466值,并将其转换为float但无法获取它。

我试过使用numberFormat和DecimalFormat以及Float.parseFloat但没有任何工作......

private void retrieveMinuteByDegreeValueFromPhp() throws IOException {
    SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFS, 0);
    SharedPreferences.Editor editor = prefs.edit();

    HttpClient httpclient=new DefaultHttpClient();
    HttpPost httppost=new HttpPost(URL_PHP_MINUTEDEGREE);
    HttpResponse response = httpclient.execute(httppost);

    if ( response.getStatusLine().getStatusCode() == 200){
        String str =  EntityUtils.toString(response.getEntity());
        float minuteByDegree = Float.valueOf(str);
        if (minuteByDegree > 0){
            editor.putFloat(MINUTEBYDEGREE, minuteByDegree);
            editor.commit();
        }
        Log.d("MinuteByDegree","Minutebydegree : " + minuteByDegree);

    }
    else {
        Log.d("MinuteByDegee","Error : " + response.getStatusLine().getStatusCode());
    }
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

感谢@Thomas,字符串中隐藏了一个错误的字符,而不是char数组。 :)