如何解决有没有办法将我的终点方向转换为数字?
因此,当我尝试将结束方向(例如N,S,E,W)转换为正1.0或负1.0以乘以最终的度/分钟的秒数时,我的 double 符号始终返回0.0。我尝试在单独的 if 语句中测试每个字母,并尝试将计算结果放入 if 语句。
我一直在测试以下坐标: 40°35'6.9288“北
public static double convertdegreesToDecimals(String strValue) {
double decimal = 0;
double sign = 1.0;
String degree = strValue.substring(0,strValue.indexOf(DEGREE));
double deg = Double.parseDouble(degree);
String minute = strValue.substring(strValue.indexOf(DEGREE)+1,strValue.indexOf(MINUTE));
double min = Double.parseDouble(minute);
String second = strValue.substring(strValue.indexOf(MINUTE)+1,strValue.indexOf(SECOND));
double sec = Double.parseDouble(second);
String direction = strValue.substring(strValue.indexOf(SECOND)+1,strValue.length());
System.out.println(direction); //prints N,S,or whatever the direction is correctly
if(direction=="S" || direction=="E"){
double sign = -1.0;
}else if(direction=="N" || direction=="W"){
double sign = 1.0;
}
decimal = ( (deg + (min / 60.0) + (sec / 3600.0) ) * sign);
return decimal;
}
我希望 double 符号在方向为S或W时等于-1.0,在方向为N或E时等于1.0。我计算的度/分的秒数为正确的除符号外,字符串方向总是返回预期结果(N,S,E,W)。当我在 if println 语句时, / strong>语句,它们没有执行,这使我认为 if 语句一定有问题。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。