1

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

78.38582246667-17.4532826666

但我需要像:

78.385 - 17.453

我也在使用 DecimalFormating。但我没有得到小数点后 3 位的 Logitude 和 Latitude。

这是我的示例代码:

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);
}   
4

1 回答 1

7

使用下面的代码行

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

代替

DecimalFormat dec = new DecimalFormat("#.000 EUR");
于 2012-06-06T07:28:29.357 回答