我想将这种格式的字符串坐标50.3332W
转换为等效的float表示形式-50.3332
。
目前,我有类似这样的内容,但是它只是替换了W
字符,并将减号放在最后。
NSString *newtest = [_myTextField.text stringByReplacingOccurrencesOfString:@"W" withString:@"-"];
在这方面的任何帮助将是有帮助的。
最佳答案
// *** Your string value ***
NSString *value = @"50.3332W";
// *** Remove `W` from string , convert it to float and make it negative by multiplying with -1.
CGFloat floatValue = [[value stringByReplacingOccurrencesOfString:@"W" withString:@""] floatValue] * -1;
// ** Result negative float value without `W` **
NSLog(@"%f",floatValue);
关于ios - 将坐标字符串转换为浮点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36328129/