label.text = String(format:"%.1f hour", theOrder.bookingMins/60.0)
The above code just get the error:'Int' is not convertible to 'Double'
上面的代码得到的错误是:'Int'不能转换为'Double'
bookingMins
is of type Int, so how do I convert an Int to a Double in Swift? Seems not as simple as in C.
bookingMins是Int类型的,那么如何在Swift中将Int转换为Double呢?似乎没有C语言那么简单。
2 个解决方案
#1
76
Try Double(theOrder.bookingMins)
尝试双(theOrder.bookingMins)
#2
2
label.text = String(format:"%.1f hour", Double(theOrder.bookingMins) /60.0)
#1
76
Try Double(theOrder.bookingMins)
尝试双(theOrder.bookingMins)
#2
2
label.text = String(format:"%.1f hour", Double(theOrder.bookingMins) /60.0)