我不能将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