정밀도를 잃지 않고 문자열을 double로 변환 할 수 없습니다.Double을 String으로 변환. 정밀도를 잃습니다.
봐
Double latitude = gps.getLatitude();
String latitude1 = Double.toString(latitude);
new onbuttonclickHttpPost().execute(latitude1);
여기에 나머지 비동기 클래스입니다. 그리고 POST에 내가 문자열을 보내고 그것은
public class onbuttonclickHttpPost extends AsyncTask<String, Void, Void> {
@Override
protected Void doInBackground(String... f_url) {
byte[] result = null;
String str = "";
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("_HERE_GO_MY_URL");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("lng", f_url[0]));
nameValuePairs.add(new BasicNameValuePair("lat", "X"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){
result = EntityUtils.toByteArray(response.getEntity());
str = new String(result, "UTF-8");
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
return null;
}
/**
* on getting result
*/
protected void onPostExecute(String result) {
// something with data retrieved from server in doInBackground
}
}
문자열이 3.0
처럼 보이지만 전 정밀도로 변환하는 방법 3.518972061574459
해야 허용되지 않습니다 3.0?
편집 : 추가 조금 더 코드
더블을 사용하지 않는 특별한 이유가 그 부정확 한 부정확하지만 아니다. 첫 번째 과제 전에 위도가 잘 리게 될 가능성이 있습니다 ... 전체 코드 게시 – Reimeus
http://stackoverflow.com/questions/20353319/java-double-to-string-with-specific-precision 체크 아웃 십진 형식, 빠른 검색 해피 코딩 – RedKlouds
어떻게 이런 일이 발생할 수 있습니까? 너의 두배가 3.518972061574459라고 확신합니까? 더 많은 코드를 게시 할 수 있습니다 – Jerome