我只是从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());
}
}
有什么想法吗?
答案 0 :(得分:0)
感谢@Thomas,字符串中隐藏了一个错误的字符,而不是char数组。 :)