ios - 使用 Swift 在 numberPad 中添加点而不是逗号

标签 ios swift textfield numpad

我搜索如何使用 Swift 5 在文本字段的数字键盘中用点替换逗号分隔符。

我尝试过,但没有成功。

let commaValue = textField.text!
let decimalValue = Double(commaValue.replacingOccurrences(of: ",", with: "."))

最佳答案

你可以使用这个:

let commaValue = "2,3"
let replaced = String(commaValue.map {
$0 == "," ? "." : $0 })

关于ios - 使用 Swift 在 numberPad 中添加点而不是逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57580628/

相关文章:

iOS 8 今日扩展 : Is it possible to add editable text field?

validation - 输入类型 ='number' 新验证删除了 Safari for iPhone iOS5 和最新的 Safari for Mac 中的前导零和格式数字

ios - 在 View Controller 之间共享 NSURLsession 委托(delegate)实现

ios - 有没有办法防止在 MapboxGL for iOS 中滚动时标注消失?

ios - 没有初始化器但有属性观察器的 Swift 类

swift - 如何将 For 中的 lets 放入表中

ios - 使用 UITextfield 文本更改更新 UITableview 单元格

IOS 动画不适用于我的动画 block

ios - 如果在 iOS 设置中禁用通知访问时安排本地通知,则不会在 iOS 13 上触发本地通知

ios - 空指针的 Xcode 静态分析