【问题标题】:What is the use of underscores in a number? [closed]数字中的下划线有什么用? [关闭]
【发布时间】:2019-04-05 07:16:06
【问题描述】:

我想了解以下语句中使用下划线背后的逻辑:

let oneMillion = 1_000_000
let oneThousand = oneMillion / 0_1_0_0_0
print(oneThousand)

此语句打印“1000”。

(1_000_000) 中的下划线有什么作用?

【问题讨论】:

标签: swift


【解决方案1】:

忽略 '_' Swift 允许您将它们插入数字中,以将它们分解成更有用的块。代码相当于:

let oneMillion = 1000000
let oneThousand = oneMillion / 01000
print(oneThousand)

【讨论】:

    猜你喜欢
    • 2015-02-27
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 2011-03-05
    • 1970-01-01
    相关资源
    最近更新 更多