如何在Swift中将大于Int.max的浮点值转换为Int [英] How to convert a floating point value greater than Int.max to Int in Swift
本文介绍了如何在Swift中将大于Int.max的浮点值转换为Int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var floatingPointValue = NSDate()。timeIntervalSince1970 * 1000
我不关心这个浮点数的整数值实际上是一个整数还是一个整数串。
解决方案
Int64
足够容纳数百万的时间间隔
年以毫秒为单位:
let milliSeconds = Int64(someDate.timeIntervalSince1970 * 1000)
let milliSecondsString = String(milliSeconds)
I want to have the integer value of the following floating point value:
var floatingPointValue = NSDate().timeIntervalSince1970 * 1000
I don't care if the integer value of this floating point number is actually an integer or a string.
解决方案
Int64
is large enough to hold a time interval of some million
years measured in milliseconds:
let milliSeconds = Int64(someDate.timeIntervalSince1970 * 1000)
let milliSecondsString = String(milliSeconds)
这篇关于如何在Swift中将大于Int.max的浮点值转换为Int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文