Hello I'm trying to convert some gps data from DMS (degrees, minutes, secondes) >> to >> DD (decimal degrees)
Now I get the wrong value out. I think the problem is of wrong usage of the vars type: int and float.
The code compiles but it returns the wrong value..
part of my code is:
// DMS string in:
saveGps("5205.6295");
void saveGps(String coord) {
int deg = coord.substring(0, 2).toInt();
int min = coord.substring(2 , 4).toInt();
int sec = coord.substring(5).toInt();
// convert to DD
float lat_dd = deg+ min / 60 + sec / (60*60); /// !!!!!
Serial.println("Lat out:");
Serial.println(lat_dd,6); // give WRONG output: 1.763056 instead of
}
Edit:
name var has to be deg instead of day..
n was for the long (has one more digit..).
I tested the values with:
Serial.println("deg: " + deg);
You define "day" but then refer to it as "dagen" and the same problem for "min" and "sec".
The other problem is that you are doing the calculation with integers. For integer arithmetic in C/C++ there is no remainder, so 10/20 is zero - not 0.5.
You can either declare day,min, sec to be float, or force the calculation to be done with floating point: