2014-12-06 2 views
0

정밀도를 잃지 않고 문자열을 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?

편집 : 추가 조금 더 코드

+2

더블을 사용하지 않는 특별한 이유가 그 부정확 한 부정확하지만 아니다. 첫 번째 과제 전에 위도가 잘 리게 될 가능성이 있습니다 ... 전체 코드 게시 – Reimeus

+0

http://stackoverflow.com/questions/20353319/java-double-to-string-with-specific-precision 체크 아웃 십진 형식, 빠른 검색 해피 코딩 – RedKlouds

+0

어떻게 이런 일이 발생할 수 있습니까? 너의 두배가 3.518972061574459라고 확신합니까? 더 많은 코드를 게시 할 수 있습니다 – Jerome

답변

0

당신이 바로 (당신은 내가 모든 소수 얻을 여기에서 볼 수 있습니다 http://goo.gl/pORXg2를)이야하고있는 방법입니다. 어쩌면 문제는 어떻게 인쇄하는지입니다.

+0

.. 어떻게 내가 namebufferPairs에 POST 데이터에 전체 dobule을 전달할 수 있습니다 – pr0metheus

0

명시 적 형식

String output=String.format("%.10f", 3.518972061574459); 

으로 String으로 이중 변환하려고하면 출력에 "3.5189720615"을 가지고 있습니다.

0

당신이

Double latitude = gps.getLatitude(); 
String latitude1 = latitude==null?"":latitude.toString() 
관련 문제