度分秒和点度互转
QString 字符串截取
1 QString degree2Dmc(double dbDegree) 2 { 3 double lon = dbDegree; 4 if (lon < 0.0) 5 lon = -dbDegree; 6 int nDegree = (int)lon; 7 double dbMin = (lon - nDegree) * 60.0; 8 int nMin = dbMin; 9 double sec = (dbMin - (int)dbMin) * 60.0; 10 11 if (dbDegree < 0.0) 12 { 13 nDegree = -nDegree; 14 } 15 16 QString textLon = QString(tr("%1%2%3\'%4\"")).arg(nDegree).arg('\xb0').arg(nMin).arg(sec, 0, 'f', 2); 17 return textLon; 18 } 19 20 double Dmc2Degree(QString strDmc) 21 { 22 QString strTemp = strDmc; 23 24 QString strSec = ""; 25 QString strMin = ""; 26 QString strDegree = ""; 27 28 int nDegree = strTemp.indexOf("°"); 29 if (nDegree != -1) 30 { 31 strDegree = strTemp.left(nDegree); 32 strTemp = strTemp.mid(nDegree + 1); 33 } 34 35 int nMin = strTemp.indexOf('\''); 36 if (nMin != -1) 37 { 38 strMin = strTemp.left(nMin); 39 strTemp = strTemp.mid(nMin + 1); 40 } 41 42 int nSec = strTemp.indexOf('\"'); 43 if (nSec != -1) 44 { 45 strSec = strTemp.left(nSec); 46 } 47 48 double dbDegree = strDegree.toDouble(); 49 double dbMin = strMin.toDouble(); 50 double dbSec = strSec.toDouble(); 51 52 double dbRet; 53 if (dbDegree < 0.0) 54 { 55 dbDegree = -dbDegree; 56 dbRet = -(dbDegree + dbMin / 60.0 + dbSec / 3600.0); 57 } 58 else 59 { 60 dbRet = dbDegree + dbMin / 60.0 + dbSec / 3600.0; 61 } 62 63 return dbRet; 64 }
标签:nDegree,分秒,qt,double,dbDegree,点度,strTemp,QString,dbMin From: https://www.cnblogs.com/warmlight/p/17462576.html