我不能將double轉換爲字符串而不會失去精度。將Double轉換爲String。丟失精度
看
Double latitude = gps.getLatitude();
String latitude1 = Double.toString(latitude);
new onbuttonclickHttpPost().execute(latitude1);
這裏是異步類休息。而在文章中,我送字符串,它是3.0這是不能接受
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
如何與全精度轉換?
編輯:補充一點的代碼
雙任何具體的原因是不精確的,但並不準確。它的可能是緯度被截斷之前的第一次作業...發佈您的完整代碼 – Reimeus 2014-12-06 13:38:54
http://stackoverflow.com/questions/20353319/java-double-to-string-with-specific-precision 退房十進制格式,只是快速搜索 快樂編碼 – RedKlouds 2014-12-06 13:42:15
這怎麼會發生?你確定你的雙倍是3.518972061574459。可能是你可以發佈更多的代碼 – Jerome 2014-12-06 13:43:55