首页 > 解决方案 > 如何将双精度值转换为 java 中的 n 个位置(给出答案,而不是问问题)

问题描述

DecimalFormat df = new DecimalFormat("0.00");//if you want over four decimal places then do->"0.0000" in brackets

TextView lattextview=findViewById(R.id.lattextview);
TextView lontextview=findViewById(R.id.longtextview);
TextView alttextview=findViewById(R.id.alttextview);
TextView accuracytextview=findViewById(R.id.accuracytextview);
TextView addresstextview=findViewById(R.id.addresstextview);

String s1 = df.format(location.getLatitude());
String s2 = df.format(location.getLongitude());
String s3 = df.format(location.getAltitude());
String s4 = df.format(location.getAccuracy());
lattextview.setText("Latitude : "+s1);
lontextview.setText("Longitude : "+s2);
alttextview.setText("Altitude : "+s3);
accuracytextview.setText("Accuracy : "+s4);

标签: javaandroiddecimalconvertersrounding-error

解决方案


推荐阅读