Gps 有没有办法减少小数点后的位数?

Gps 有没有办法减少小数点后的位数?,gps,coordinates,Gps,Coordinates,我的android应用程序有点问题。我想用手机的GPS显示当前的纬度和经度。我可以得到手机的当前坐标,但它显示为一个双值与。。。我认为小数点后有6-8位数字。有没有办法减少小数点后的位数 以下是我的代码: public class Localisation extends Activity implements LocationListener{ protected LocationManager locationManager; protected LocationListener loca

我的android应用程序有点问题。我想用手机的GPS显示当前的纬度和经度。我可以得到手机的当前坐标,但它显示为一个双值与。。。我认为小数点后有6-8位数字。有没有办法减少小数点后的位数

以下是我的代码:

public class Localisation extends Activity implements LocationListener{

protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
private String TripDescription;
private String tripID;



TextView txtLat;
String lat;
String provider;
protected String latitude, longitude;

protected boolean gps_enabled, network_enabled;


@Override

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_localisation);
    txtLat = (TextView) findViewById(R.id.textView1);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

}


@Override
public void onLocationChanged(Location location) {
    txtLat = (TextView) findViewById(R.id.textView1);
    txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());

}

@Override
public void onProviderDisabled(String arg0) {
    Log.d("Latitude","disable");

}

@Override
public void onProviderEnabled(String provider) {
    Log.d("Latitude","enable");     
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    Log.d("Latitude","status");     
}
将(浮点数或双位数)减少到6位数:

double oldVal = location.getLatitude();
double newVal = ((int) Math.round(oldVal * 1E6)) / 1E6;
与一百万的乘法将截断6位数后的所有内容。
向后除以后,数值限制为6位。

请考虑对我的答案进行向上投票,它是正确的。在这里起作用。非常感谢。