将String转换为Float Objective-C

Kir*_*iki -1 objective-c xcode4 xcode4.2

我想立即检索字符串中数据的纬度和经度.为了使用它,它必须转换为浮点数,所以我可以在这里使用它而不是浮点数:

//Create a region 

mapview.mapType = MKMapTypeSatellite;
MKCoordinateRegion newRegion;
newRegion.center.latitude = 47.808435,
newRegion.center.longitude = 9.643743;
newRegion.span.latitudeDelta = 0.00472;
newRegion.span.longitudeDelta = 0.006899;

CLLocationCoordinate2D coordinate;
coordinate.latitude = 47.808435;
coordinate.longitude = 9.643743;
Run Code Online (Sandbox Code Playgroud)

我只知道如何将字符串转换为数据,但我不知道如何将其转换为浮点数.有人知道吗?

小智 12

如果您有一个包含有效浮点数字符串表示形式的NSString实例,则可以使用:

float number = [anNSString floatValue];
Run Code Online (Sandbox Code Playgroud)