I am getting gps readings using these lines of code:
String mLatitud = String.valueOf(location.getLatitude());
String mLongitud = String.valueOf(location.getLongitude());
The problem is that in some occasions the amount of decimals varia de 6 a 15 decimales
, I need that latitud tenga 6 decimales
and longitud 5 decimales
.
How can I do that?
You can use the class
DecimalFormat
to define the number of decimals:You define the format like this:
You apply the format: