簡體   English   中英

Java.lang.numberformatexception:無效的浮點數“ 0.008466”

[英]Java.lang.numberformatexception: Invalid float “0.008466”

我只是從一個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());
    }
}

任何想法 ?

感謝@Thomas,字符串中隱藏了一個錯誤字符,但char Array中沒有。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM