NEW: Master Swift design patterns with my latest book! >>

How to convert an int to a float

Written by Paul Hudson    @twostraws

Swift's Float data type has a built-in constructor that can convert from integers with no extra work from you. For example, to convert the integer 556 into its Float equivalent, you'd use this:

let myInt = 556
let myFloat = Float(myInt)

Available from iOS 7.0

Did this solution work for you? Please pass it on!

Other people are reading…

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions.

Upgrade to the premium experience

Get all 40 projects in PDF and ePub, plus exclusive content that will take your Swift learning to the next level – buy the Hacking with Swift book today!

Click here to visit the Hacking with Swift store >>