Delete part of latitude and longitude after 6 digits

I get lat and long in this format

Latitude23.132679999999997, Longitude72.20081833333333

but I want in this format

Latitude = 23.132680 and Longitude 72.200818

how can i convert

+3
source share
6 answers
double Latitude = 23.132679999999997;
int precision =  Math.pow(10, 6);
double new_Latitude = double((int)(precision * Latitude))/precision;

This will give you only 6 digits after the decimal point.

+7
source
double d=23.132679999999997;
DecimalFormat dFormat = new DecimalFormat("#.######"); 

d= Double.valueOf(dFormat .format(d));
+3
source

, , ?

+1

DecimalFormat df = new DecimalFormat("#,###,##0.00");
System.out.println(df.format(364565.14343));
0

,

latitude = latitude.substring(0,latitude.indexOf(".")+6);

Of course, you should check that after the "." must be at least 6 characters. by checking the length of the string

0
source

Once I solved my problem like this -

String.format("%.6f", latitude);

The return value is a string. Therefore, you can use this if you need the result of a string.

If you need to double, you can convert using the method Double.parseDouble().

0
source

All Articles