remove latitude and longitude fraction part after 6 digit

江枫思渺然 提交于 2019-12-05 19:10:18
Shakti Malik
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.

Eduardo
Dheeresh Singh

can use like

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!