Convert CGFloat to NSNumber in Swift Convert CGFloat to NSNumber in Swift ios ios

Convert CGFloat to NSNumber in Swift


In Swift 3.0

let myFloat : CGFloat = 1234.5let myNumber = NSNumber(value: Float(myFloat))

or

let myNumber = NSNumber(value: Double(myFloat))

In Swift 2

let myNumber = NSNumber(double: myFloat.native)

or

let myNumber = NSNumber(double: Double(myFloat))

or

let myNumber = NSNumber(float: Float(myFloat))


For Swift 3.1

var final_price: CGFloat = 12.34let num = final_price as NSNumber


Swift 3

let myNumber = NSNumber(value: Float(myCGFloat))


matomo