system
March 11, 2014, 5:29pm
1
I have the following function which I need to convert some coordinates:
double convertRawToDecimal(double latOrLong){
int decimalDegrees = (int) latOrLong / 100;
Serial.println(decimalDegrees);
double minutes = latOrLong - decimalDegrees * 100;
Serial.println(minutes);
double temp = minutes/60.0;
Serial.println(temp);
double result = decimalDegrees +temp;
return result;
}
The important part is happening where I divide minutes by 60.
I call the method with for example 4730.59 and when I print out the temp variable which should hold something like 0.5098333 it prints out 0.51 . Now I am wondering is the println method pulling my leg or is the value stored in temp really 0.51
Thanks for helping out
system
March 11, 2014, 5:32pm
2
multiply the number by 1000 and see how many significant digits you get.
Try:
Serial.println(minutes,4);
Note also that double & float are the same size in an arduino context; you're not getting any additional precision by specifying double.
smithy
March 11, 2014, 10:03pm
5
When you calculate using your double it won´t round, all decimals are used for calculation.
system
March 11, 2014, 10:30pm
6
TempleClause:
Now I am wondering is the println method pulling my leg
See Reply #3 . The println() method is doing what it is supposed to, it is just not what you expected.
I'd like to also add that unless you have a due, there is also no difference between float and double, both have the same precision.