Decimal to Double conversion in Swift 3

后端 未结 7 1442
春和景丽
春和景丽 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 01:53

    Solution that works in Swift 4

    let double = 3.14
    let decimal = Decimal(double)
    let doubleFromDecimal = NSDecimalNumber(decimal: decimal).doubleValue
    print(doubleFromDecimal)
    

提交回复
热议问题