我想比较两个双重值:
for(int i=0;i<count;i++){
Double i1=Double.parseDouble(pref.getString("longitude"+i, null));
Double i2=Double.parseDouble(pref.getString("latitude"+i,null));
Log.i("Longitude", i1+"");
Log.i("Latitude",i2+"");
Log.i("Longitude1",longitude+"");
Log.i("Latitude1", latitude+"");
Log.i("note",pref.getString("note"+i, null));
if(longitude==i1&&latitude==i2) {
String note=pref.getString("note"+i, null);
txt.setText(note);
}
}
Run Code Online (Sandbox Code Playgroud)
共享首选项中有一个组合与经度和纬度相匹配,但是当我比较它没有为textview txt分配任何值时.但是在log中有纬度和纬度的相同值.任何一个请告诉我这里有什么错误比较为什么它不执行txt.settext语句?
我认为存在准确性问题 - 绝对严格地表示 float 或 double cannon 类型。当我需要比较两个双打时,我会使用这样的东西
double doubleToCompare1 = some double value;
double doubleToCompare2 = another double value;
double EPS = 0.00001;
if(Math.abs(doubleToCompare1-doubleToCompare2)<EPS){
// assuming doubles are equals
}
Run Code Online (Sandbox Code Playgroud)
EPS 值取决于您需要的准确性。对于坐标,我记得它是逗号后的 6 或 7 个符号。
假定latitude和longitude要Double过,尝试调用doubleValue两个:
if(longitude.doubleValue() == i1.doubleValue() && latitude.doubleValue() == i2.doubleValue())
Run Code Online (Sandbox Code Playgroud)
或者只是使用 equals
if(longitude.equals(i1) && latitude.equals(i2))
Run Code Online (Sandbox Code Playgroud)
它来自引擎盖下的第一行.
| 归档时间: |
|
| 查看次数: |
7409 次 |
| 最近记录: |