ios - 将坐标字符串转换为浮点

标签 ios objective-c

我想将这种格式的字符串坐标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/

相关文章:

ios - 在曲线形状图层上绘制边框

ios - 在 iOS 中使用 ffmpeg 进行 hls 直播

ios - 如何仅查看具有特定主题标签的推文

ios - Swift 3 URLSession 发送空请求

ios - 线程 1 信号 SIGABRT 无法加载 Main.Storyboard

ios - 动态更改 CustomTableViewCell 上的图像

ios - 神奇的记录删除一对多关系所有 child

objective-c - 是否有用于 gSOAP 的 Objective-C 包装器?

objective-c - 向 NSView 添加 subview 会显示,但无法删除

iOS - 带摘要的网络调用