如何获得最多3个小数点的GPS经度和纬度值?

时间:2012-06-06 07:23:54

标签: android gps

我开发了一个GPS应用程序,我得到的值如下:

78.38582246667-17.4532826666

但我需要:

78.385 - 17.453

我也在使用DecimalFormating。但我没有得到逻辑和纬度最多3个小数点。

这是我的示例代码:

if (location != null) {         
    String credits = String.format("Current Location \n Longitude: %1$s \n Latitude: %2$s", location.getLongitude(), location.getLatitude());       
    Double number = Double.valueOf(credits);
    DecimalFormat dec = new DecimalFormat("#.000 EUR");
    String message = dec.format(number);
    Toast.makeText(Clockin.this, message, Toast.LENGTH_SHORT).show();
    //txt.setText(message); 
    System.out.println("GPS.."+message);
}   

1 个答案:

答案 0 :(得分:7)

使用以下代码行

DecimalFormat dec = new DecimalFormat("#.###");

而不是

DecimalFormat dec = new DecimalFormat("#.000 EUR");
相关问题