【问题标题】:No * candidates produce the expected result type FloatingPointRoundingRule否 * 候选人产生预期的结果类型 FloatingPointRoundingRule
【发布时间】:2025-12-27 13:15:17
【问题描述】:

在 Swift 3 中,我收到以下错误(在 Swift 2 中没有发生):

没有 * 候选人产生预期的结果类型 FloatingPointRoundingRule

我不知道我需要做什么来修复它。

我正在尝试将纬度小数转换为度/分/秒

extension CLLocationDegrees {        
    mutating func toLatitudeSeconds() -> String {
        var seconds = Int(round(self * 3600)) //error here
        // etc ...
    }
}

【问题讨论】:

    标签: ios swift3 rounding


    【解决方案1】:

    舍入函数已更改为在实例上调用,而不是全局函数。您基本上是在尝试执行 self.round(self*3600) 这不起作用,因为 round 函数不接受参数或 FloatingPointRoundingRule 类型的参数。

    你可能想要:

    var seconds = Int((self*3600).rounded())
    

    【讨论】:

    • 我真的希望他们在每次主要版本更新到 swift 时停止进行这样的更改,选择一种方式并坚持下去。抱歉,您的回答有效,谢谢
    • 他们这样做是为了round,但为什么不为ceilfloor...?
    • @shim 他们可能希望你使用round 而不是ceilfloor。例如x.round(.up)x.round(.down)
    • 您的意思是rounded(.up).down
    最近更新 更多