remove latitude and longitude fraction part after 6 digit

时间秒杀一切 提交于 2020-01-02 08:01:03

问题


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


回答1:


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.




回答2:


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

d= Double.valueOf(dFormat .format(d));



回答3:


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.




回答4:


So you want round a double to an arbitrary number of digits, don't you?




回答5:


can use like

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



回答6:


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



来源:https://stackoverflow.com/questions/10599808/remove-latitude-and-longitude-fraction-part-after-6-digit

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