i get lat and long in this format
Latitude23.132679999999997, Longitude72.20081833333333
but i want to in this format
Latitude = 23.132680 and Longitude 72.200818
how can i convert
i get lat and long in this format
Latitude23.132679999999997, Longitude72.20081833333333
but i want to in this format
Latitude = 23.132680 and Longitude 72.200818
how can i convert
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 decimal point.
double d=23.132679999999997;
DecimalFormat dFormat = new DecimalFormat("#.######");
d= Double.valueOf(dFormat .format(d));
Once I solved my problem like this -
String.format("%.6f", latitude);
Return value is string. So you can use this if you need string result.
If you need double you can convert using Double.parseDouble()
method.
can use like
DecimalFormat df = new DecimalFormat("#,###,##0.00");
System.out.println(df.format(364565.14343));
If you have Latitude and Longitude as String then you can do
latitude = latitude.substring(0,latitude.indexOf(".")+6);
Of course you should check that there are at least 6 characters after "." by checking string length