Issue with nf() and Incompatible Types
in
Programming Questions
•
2 years ago
Hi all,
I'm struggling with a simple problem - one that I've dealt with before, but am still stuck...
Basically my issue is that I am reading GPS coordinates on Android, and want to use nf() to make sure the Lat/Lon always have two digits before the decimal point (as I'm using .substring later on to split the degrees, minutes, seconds, etc...)
Currently, I have float variables declared, then setting it to the Latitude (which is natively a double)
currentLatitude = (float)location.getLatitude();
...
then later on I cast it as a String
String Latitude = str(currentLatitude);
String LatH = Latitude.substring(0,2);
String LatM = Latitude.substring(3,5);
String LatS = Latitude.substring(5,7);
...
I'm trying to input the nf() conversion right when I get the GPS data, so instead of
currentLatitude = (float)location.getLatitude();
it would be
currentLatitude = nf((float)location.getLatitude(), 2, 4);
The java compiler in the console is giving me an "incompatible types" error, saying that it is finding a String:
incompatible types
[javac] found : java.lang.String
[javac] required: float
[javac] currentLatitude = nf((float)location.getLatitude(), 2, 4);
[javac] ^
[javac] 1 error
which is confusing, because currentLatitude is declared as a float, and I'm expressly casting it as a float inside the first argument for the nf() method...
I'm in the stuck/frustrated phase where I'm sure there is a simple solution, but am failing to see it...
If anyone has any thoughts, it would be appreciated.
Thanks!
~ J
1