【发布时间】:2016-06-14 00:55:23
【问题描述】:
我正在制作一个计算器应用程序,当我达到一个高数字时它会崩溃。 这是代码。
var accumulator: Double = 0.0
func updateDisplay() {
// If the value is an integer, don't show a decimal point
let iAcc = Int(accumulator)
if accumulator - Double(iAcc) == 0 {
numField.text = "\(iAcc)"
} else {
numField.text = "\(accumulator)"
}
}
这是错误
fatal error: floating point value can not be converted to Int because it is greater than Int.max
如果有人能帮忙那就太好了!
【问题讨论】:
-
什么是
accumulator,你能在运行时打印accumulator吗?