views:

1927

answers:

1

I'm trying to convert CLLocation latitude / longitude to a string. I can successfully do this with the follow code:

// extract latitude from CLLocation object and cast to string
NSString *latitude = [[NSString alloc] initWithFormat:@"%g°", location.coordinate.latitude];

this gives me a value like: 34.10111º. I would like this number as a pure string without the º degree symbol.

Should I init the string with a different format?

I tried initing with the format @"%d" and the string comes out to a different number altogether.

+10  A: 

You have a degree symbol in your format string. Remove it and you should be fine.

As to the other part of your question, %d as a format specifier wants an integer, and you're giving it a floating-point number. Your %g is correct, as would be %e or %f.

Jim Puls
That's definitely it! Thanks a million!
Buffernet