Decimal to Double conversion in Swift 3

后端 未结 7 1443
春和景丽
春和景丽 2020-12-29 01:42

I\'m migrating a project from Swift 2.2 to Swift 3, and I\'m trying to get rid of old Cocoa data types when possible.

My problem is

7条回答
  •  伪装坚强ぢ
    2020-12-29 02:08

    Another solution that works in Swift 3 is to cast the Decimal to NSNumber and create the Double from that.

    let someDouble = Double(someDecimal as NSNumber)
    

    As of Swift 4.2 you need:

    let someDouble = Double(truncating: someDecimal as NSNumber)
    

提交回复
热议问题