gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:30:57 26 4
gpt4 key购买 nike

我搜索如何使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com